Bughunting 2. Reconsider datamodel of mongodb and user/pass storage
This commit is contained in:
+7
-4
@@ -17,14 +17,17 @@ password = getpass.getpass("Password: ")
|
|||||||
uuid = str(uuid.uuid4())
|
uuid = str(uuid.uuid4())
|
||||||
email = input("Email-adres: ")
|
email = input("Email-adres: ")
|
||||||
full_name = input("Volledige naam: ")
|
full_name = input("Volledige naam: ")
|
||||||
|
list_id = ""
|
||||||
|
|
||||||
col = db["cred"]
|
user_cred = {"username": username, "password": password, "uuid": uuid}
|
||||||
|
user_info = {"uuid":uuid, "email": email, "name": full_name ,"listid": list_id}
|
||||||
|
|
||||||
mydict = {"username": username, "password": password, "uuid": uuid, "email": email, "name": full_name}
|
|
||||||
if col.find_one({"username": username}):
|
if db.user_cred.find_one({"username": username}):
|
||||||
print("Username already exists\n")
|
print("Username already exists\n")
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
x = col.insert_one(mydict)
|
cred_record = db.user_cred.insert_one(user_cred)
|
||||||
|
info_record = db.user_info.insert_one(user_info)
|
||||||
print("User created")
|
print("User created")
|
||||||
|
|
||||||
|
|||||||
+14
-6
@@ -1,13 +1,21 @@
|
|||||||
|
import uuid
|
||||||
import pymongo
|
import pymongo
|
||||||
import getpass
|
import getpass
|
||||||
|
|
||||||
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017/")
|
config = {
|
||||||
|
"username": "admin",
|
||||||
|
"password": "pass",
|
||||||
|
"server": "localhost:27017",
|
||||||
|
}
|
||||||
|
connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"])
|
||||||
|
client = pymongo.MongoClient(connector)
|
||||||
|
db = client["groclist"]
|
||||||
|
|
||||||
|
|
||||||
username = input("Username :")
|
username = input("Username :")
|
||||||
#password = getpass.getpass("Password: ")
|
#password = getpass.getpass("Password: ")
|
||||||
|
|
||||||
mydb = myclient["groclist_db"]
|
userid = db.user_cred.find_one({"username": username})
|
||||||
mycol = mydb["groclist_users"]
|
email = db.user_info.find_one({"uuid": userid{"uuid": 1} ,"name": 1, "email": 1})
|
||||||
|
|
||||||
email = mycol.find_one({"username": username}, {"_id": 0, "name": 1, "email": 1})
|
print (userid, email)
|
||||||
|
|
||||||
print (email)
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ def login():
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
username = request.form["username"]
|
username = request.form["username"]
|
||||||
password = request.form["password"]
|
password = request.form["password"]
|
||||||
if db.cred.find_one({"username": username, "password": password}):
|
if db.user_cred.find_one({"username": username, "password": password}):
|
||||||
auth_user_id = db.cred.find_one({"username": username},{"uuid", 1})
|
auth_user_id = db.user_cred.find_one({"username": username},{"uuid", 1})
|
||||||
if auth_user_id:
|
if auth_user_id:
|
||||||
app.logger.info(auth_user_id)
|
app.logger.info(auth_user_id)
|
||||||
return render_template("welcome.html", id=auth_user_id["uuid"])
|
return render_template("welcome.html", id=auth_user_id["uuid"])
|
||||||
|
|||||||
Reference in New Issue
Block a user