mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
from flask import Blueprint, redirect, url_for
|
|
from flask_login import current_user
|
|
from flask_security.decorators import auth_required
|
|
|
|
from . import security, settings
|
|
from .model_dependent_funs import active_semester_str
|
|
|
|
bp = Blueprint("main", __name__, root_path="/", template_folder="templates")
|
|
|
|
|
|
@bp.app_context_processor
|
|
def util_processor():
|
|
author_email = "mobitar@students.uni-mainz.de"
|
|
repo_url = settings["repo_url"]
|
|
|
|
footer = f"This website is still under development (beta release)! If you have any questions, find any bugs or want some feature, please write a formless email (german/english) to Mo Bitar: <a href='mailto:{author_email}'>{author_email}</a><br><br>AdvLabDB - <a href={repo_url} target='_blank' rel='noopener noreferrer'>Source code</a>"
|
|
|
|
return dict(active_semester_str=active_semester_str, current_user=current_user, footer=footer)
|
|
|
|
|
|
@security.login_context_processor
|
|
def login_context_processor():
|
|
return dict(message=settings.get("login_view_message"))
|
|
|
|
|
|
@bp.route("/")
|
|
def index():
|
|
if current_user.has_role("admin"):
|
|
endpoint_base = "admin"
|
|
elif current_user.has_role("assistant"):
|
|
endpoint_base = "assistant"
|
|
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:
|
|
current_user.set_last_semester_as_active()
|
|
|
|
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:
|
|
url = url_for(endpoint_base + ".index")
|
|
|
|
return redirect(url)
|
|
|
|
|
|
@bp.route("/user-settings")
|
|
@auth_required()
|
|
def user_settings():
|
|
if current_user.has_role("admin"):
|
|
role = "admin"
|
|
else:
|
|
role = "assistant"
|
|
|
|
url = url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id)
|
|
|
|
return redirect(url)
|