Code review and sanitation. More understanding of concepts
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import pymongo
|
||||
from flask import Flask, request, render_template, redirect, url_for
|
||||
|
||||
# initialize connection to database
|
||||
app = Flask(__name__)
|
||||
config = {
|
||||
"username": "admin",
|
||||
"password": "pass",
|
||||
"server": "localhost:27017",
|
||||
}
|
||||
connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"]
|
||||
client = pymongo.MongoClient(connector)
|
||||
db = client["groclist"]
|
||||
|
||||
@app.route("/")
|
||||
def main():
|
||||
return render_template("login.html")
|
||||
|
||||
@app.route("/login", methods=["POST"])
|
||||
def login()
|
||||
error = None
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
if db.cred.find_one({"username": username, "password": password})
|
||||
auth_user_id = db.cred.find_one({"username": username},{"_id", 1})
|
||||
return redirect(url_for("welcome", id=auth_user_id["_id"]))
|
||||
else:
|
||||
error = "Usernaam of wachtwoord onbekend, probeer opnieuw"
|
||||
return render_template("login.html", error=error)
|
||||
|
||||
@app.route("/welcome")
|
||||
def welcome(id)
|
||||
|
||||
Reference in New Issue
Block a user