1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-09-19 18:31:16 +00:00

Add post-login

This commit is contained in:
Mo 2022-09-17 15:55:09 +02:00
parent 6dd02d3fbc
commit d18579059a
2 changed files with 34 additions and 0 deletions

View file

@ -81,4 +81,5 @@ def set_config(app, data_dir: Path):
} }
app.config["SECURITY_PASSWORD_SALT"] = secrets["SECURITY_PASSWORD_SALT"] app.config["SECURITY_PASSWORD_SALT"] = secrets["SECURITY_PASSWORD_SALT"]
app.config["SECURITY_PASSWORD_LENGTH_MIN"] = settings.getint("SECURITY_PASSWORD_LENGTH_MIN", 15) app.config["SECURITY_PASSWORD_LENGTH_MIN"] = settings.getint("SECURITY_PASSWORD_LENGTH_MIN", 15)
app.config["SECURITY_POST_LOGIN_VIEW"] = "/post-login"
# TODO: app.config["SECURITY_LOGIN_USER_TEMPLATE"] = # TODO: app.config["SECURITY_LOGIN_USER_TEMPLATE"] =

View file

@ -25,6 +25,39 @@ def index():
else: else:
return redirect(url_for("security.login")) return redirect(url_for("security.login"))
url = url_for(endpoint_base + ".index")
return redirect(url)
@bp.route("/post-login")
@auth_required()
def post_login():
current_active_semester = current_user.active_semester
if current_active_semester.done:
last_semester = Semester.lastSemester()
if not last_semester.done:
try:
current_user.active_semester = last_semester
db.session.commit()
except Exception as ex:
flash(str(ex), "error")
db.session.rollback()
else:
flash(
f"Active semester changed to {last_semester} because the semester {current_active_semester} was marked as done!",
"warning",
)
if current_user.has_role("admin"):
endpoint_base = "admin"
else:
endpoint_base = "assistant"
if current_user.login_count == 1: if current_user.login_count == 1:
url = url_for(endpoint_base + "_docs.index") url = url_for(endpoint_base + "_docs.index")
else: else: