Login against the mongo database is working

This commit is contained in:
2022-03-13 09:49:28 +01:00
parent da86395744
commit 4db0b1943c
2 changed files with 12 additions and 4 deletions
+11 -3
View File
@@ -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)