diff --git a/auth.py b/auth.py index e909886..8cd4d5e 100644 --- a/auth.py +++ b/auth.py @@ -52,11 +52,16 @@ def login(): if user.group_id>0: login_user(user) return redirect(url_for("lists.home")) - flash("Invalid key credentials.") + # flash("Invalid key credentials.") Log.info(f"Authorization failure for user '{request.form["name"]}' ") - resp = make_response(render_template("login.html")) + login_failed = request.method == "POST" + resp = make_response(render_template( + "login.html", + name_placeholder="Sorry" if login_failed else "Name", + password_placeholder="Try again" if login_failed else "Password", + )) resp.set_cookie('username', '') return resp @@ -100,14 +105,16 @@ def change_pwd(): pwd_old = request.form["password_old"] pwd_new1 = request.form["password_new1"] pwd_new2 = request.form["password_new2"] - if current_user.check_password(pwd_old): - if pwd_new1 == pwd_new2: - current_user.set_password(pwd_new2) - db.session.commit() - return redirect(url_for("lists.home")) + if not current_user.check_password(pwd_old): + flash("Invalid old credentials") + Log.info(f"Authorization failure for user '{current_user.name}' ") + elif pwd_new1 != pwd_new2: flash("New Passwords are not identical") - flash("Invalid credentials") - Log.info(f"Authorization failure for user '{request.form["name"]}' ") + else: + current_user.set_password(pwd_new2) + db.session.commit() + return redirect(url_for("lists.home")) + + return redirect(url_for("auth.change_pwd")) - return render_template(url_for("lists.home")) return render_template("change_pwd.html") diff --git a/templates/change_pwd.html b/templates/change_pwd.html index 5f4626d..02bb1cb 100644 --- a/templates/change_pwd.html +++ b/templates/change_pwd.html @@ -1,6 +1,11 @@ {% extends "base.html" %} {% block content %}