Code review and sanitation. More understanding of concepts

This commit is contained in:
2022-03-15 20:57:21 +01:00
parent e9ca0e90d5
commit ba40af743d
3 changed files with 49 additions and 13 deletions
+14 -12
View File
@@ -2,7 +2,10 @@ import pymongo
from flask import Flask, request, render_template, url_for, redirect
app = Flask(__name__)
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017")
mydb = myclient["groclist_db"]
mycol_users = mydb["groclist_users"]
username=""
@app.route("/", methods=['GET', 'POST'])
def groclist_home():
@@ -15,29 +18,28 @@ def groclist_home():
return render_template('index.html',error=error)
@app.route("/welcome")
def groclist_welcome():
return render_template("welcome.html")
@app.route("/login", methods=['GET', 'POST'])
def groclist_login():
error = None
if request.method == 'POST':
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017")
mydb = myclient["groclist_db"]
mycol = mydb["groclist_users"]
username = request.form['username']
password = request.form['password']
name = ""
if mycol.find_one({"username": username, "password": password}):
# for user_info in mycol.find({}, {"name": 0}):
# print("Welkom", user_info)
if mycol_users.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)
@app.route("/welcome", methods=['GET', 'POST'])
def groclist_welcome():
if request.method == 'GET':
userid = mycol_users.find_one({"username": username}, {"_id": 1})
print(userid)
return render_template("welcome.html", userid=userid)
else:
error = "Userid is niet bekend. Database defect"
return render_template("index.html", error=error)
app.add_url_rule("/welcome", "welcome", groclist_welcome)