bughunting for /login

This commit is contained in:
2022-03-16 13:46:10 +01:00
parent ba40af743d
commit 8ac4d3efc0
5 changed files with 44 additions and 23 deletions
+14 -6
View File
@@ -2,21 +2,29 @@ import pymongo
import getpass import getpass
import uuid import uuid
myclient = pymongo.MongoClient("mongodb://admin:pass@localhost:27017/") # initialize connection to database
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: ")
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: ")
mydb = myclient["groclist_db"] col = db["cred"]
mycol = mydb["groclist_users"]
mydict = {"username": username, "password": password, "groclist_uuid": uuid, "email": email, "name": full_name} mydict = {"username": username, "password": password, "uuid": uuid, "email": email, "name": full_name}
if mycol.find_one({"username": username}): if col.find_one({"username": username}):
print("Username already exists\n") print("Username already exists\n")
exit() exit()
else: else:
x = mycol.insert_one(mydict) x = col.insert_one(mydict)
print("User created") print("User created")
+23 -14
View File
@@ -8,26 +8,35 @@ config = {
"password": "pass", "password": "pass",
"server": "localhost:27017", "server": "localhost:27017",
} }
connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"] connector = "mongodb://{}:{}@{}".format(config["username"],config["password"], config["server"])
client = pymongo.MongoClient(connector) client = pymongo.MongoClient(connector)
db = client["groclist"] db = client["groclist"]
@app.route("/") @app.route("/")
def main(): def main():
return render_template("login.html") return render_template("index.html")
@app.route("/login", methods=["POST"]) @app.route("/login", methods=["GET","POST"])
def login() def login():
error = None error = None
username = request.form["username"] if request.method == "POST":
password = request.form["password"] username = request.form["username"]
if db.cred.find_one({"username": username, "password": password}) password = request.form["password"]
auth_user_id = db.cred.find_one({"username": username},{"_id", 1}) if db.cred.find_one({"username": username, "password": password}):
return redirect(url_for("welcome", id=auth_user_id["_id"])) auth_user_id = db.cred.find_one({"username": username},{"uuid", 1})
else: if auth_user_id:
error = "Usernaam of wachtwoord onbekend, probeer opnieuw" app.logger.info(auth_user_id)
return render_template("login.html", error=error) return render_template("welcome.html", id=auth_user_id["uuid"])
else:
return render_template("404.html")
else:
error = "Usernaam of wachtwoord onbekend, probeer opnieuw"
return render_template("login.html", error=error)
@app.route("/welcome") @app.route("/welcome/<id>", methods=['GET'])
def welcome(id) def welcome(id):
print("Hello: ", id)
# start server with run method
if __name__ == "__main__":
app.run(debug=True)
+4
View File
@@ -0,0 +1,4 @@
{% extends "base.html" %}
{% block content %}
<h2>not found</h2>
{% endblock %}
+2 -2
View File
@@ -11,7 +11,7 @@
<p class="important"> <p class="important">
Welkom bij Groclist Welkom bij Groclist
</p> </p>
<form method="post" action="/"> <form method="get" action="/login">
<input type="submit" value="Inloggen" name="login"/> <input type="submit" value="Inloggen">
</form> </form>
{% endblock %} {% endblock %}
+1 -1
View File
@@ -6,7 +6,7 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>Please login</h1> <h2>Please login</h2>
<br> <br>
<form action="" method="post"> <form action="" method="post">
<input type="text" placeholder="Username" name="username" value="{{ <input type="text" placeholder="Username" name="username" value="{{