|
|
@@ -173,7 +173,7 @@ def login():
|
|
|
if not password:
|
|
|
flash("Can't set a blank password")
|
|
|
return redirect(url_for("login"))
|
|
|
-
|
|
|
+
|
|
|
salt = bcrypt.gensalt()
|
|
|
user.passhash = bcrypt.hashpw(password.encode(), salt)
|
|
|
db.session.commit()
|
|
|
@@ -286,7 +286,7 @@ def admin():
|
|
|
db.session.commit()
|
|
|
flash("Reset user's password succesfully", category="success")
|
|
|
return redirect(url_for("admin"))
|
|
|
-
|
|
|
+
|
|
|
if newusername := request.form.get("username-add"):
|
|
|
newuser = User()
|
|
|
newuser.username = newusername
|
|
|
@@ -295,9 +295,24 @@ def admin():
|
|
|
flash("New user added successfully", category="success")
|
|
|
return redirect(url_for("admin"))
|
|
|
|
|
|
+ if newadminid := request.form.get("userid-admin"):
|
|
|
+ newadmin = db.session.execute(
|
|
|
+ db.select(User).where(User.id == newadminid)
|
|
|
+ ).scalar_one_or_none()
|
|
|
+
|
|
|
+ if newadmin.is_admin:
|
|
|
+ flash("User is already an admin", category="warning")
|
|
|
+ return redirect(url_for("admin"))
|
|
|
+
|
|
|
+ newadmin.is_admin = True
|
|
|
+ db.session.commit()
|
|
|
+ flash("User is now an admin", category="success")
|
|
|
+ return redirect(url_for("admin"))
|
|
|
+
|
|
|
users = db.session.execute(db.select(User)).scalars().all()
|
|
|
return render_template("admin.html", users=users)
|
|
|
|
|
|
+
|
|
|
@app.route("/logout", methods=["POST"])
|
|
|
def logout():
|
|
|
session.pop("userid", None)
|