Login against the mongo database is working
This commit is contained in:
+1
-1
@@ -8,9 +8,9 @@ password = getpass.getpass("Password: ")
|
||||
mydb = myclient["groclist_db"]
|
||||
mycol = mydb["groclist_users"]
|
||||
|
||||
#mydict = {"username": username, "password": enc_password}
|
||||
if mycol.find_one({"username": username, "password": password}):
|
||||
print("login success\n")
|
||||
# PS: werkt niet # uuid = mycol.find_one({groclist_uuid})
|
||||
exit()
|
||||
else:
|
||||
print("Login Failed")
|
||||
|
||||
+11
-3
@@ -1,7 +1,9 @@
|
||||
import pymongo
|
||||
from flask import Flask, request, render_template, url_for, redirect
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/", methods=['GET', 'POST'])
|
||||
def groclist_home():
|
||||
error = None
|
||||
@@ -21,10 +23,16 @@ def groclist_welcome():
|
||||
def groclist_login():
|
||||
error = None
|
||||
if request.method == 'POST':
|
||||
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
|
||||
error = 'Username of wachtwoord onbekend. Probeer opnieuw'
|
||||
else:
|
||||
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017")
|
||||
mydb = myclient["groclist_db"]
|
||||
mycol = mydb["groclist_users"]
|
||||
username = request.form['username']
|
||||
password = request.form['password']
|
||||
if mycol.find_one({"username": username, "password": password}):
|
||||
return redirect(url_for('groclist_welcome'))
|
||||
else:
|
||||
error = 'Username of wachtwoord onbekend. Probeer opnieuw'
|
||||
|
||||
return render_template("login.html", error=error)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user