diff --git a/advlabdb/config.py b/advlabdb/config.py index 2eb01fa..1106ead 100644 --- a/advlabdb/config.py +++ b/advlabdb/config.py @@ -81,4 +81,5 @@ def set_config(app, data_dir: Path): } 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_POST_LOGIN_VIEW"] = "/post-login" # TODO: app.config["SECURITY_LOGIN_USER_TEMPLATE"] = diff --git a/advlabdb/routes.py b/advlabdb/routes.py index 49d248e..7db5a08 100644 --- a/advlabdb/routes.py +++ b/advlabdb/routes.py @@ -25,6 +25,39 @@ def index(): else: 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: url = url_for(endpoint_base + "_docs.index") else: