mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-04 22:40:30 +00:00
Add post-login
This commit is contained in:
parent
6dd02d3fbc
commit
d18579059a
2 changed files with 34 additions and 0 deletions
|
@ -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"] =
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue