Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/auth/zeus.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ def authorized() -> typing.Any:
username = me.json().get("username", "").lower()

user = User.query.filter_by(username=username).first()
# pylint: disable=R1705
if username and user:
return login_and_redirect_user(user)
elif username:

if not user:
user = create_user(username)
return login_and_redirect_user(user)

flash("You're not allowed to enter, please contact a system administrator")
return redirect(url_for("general_bp.home"))
roles = me.json().get("roles", [])
user.admin = "bestuur" in roles or "haldis_admin" in roles

db.session.add(user)
db.session.commit()

return login_and_redirect_user(user)

def init_oauth(app):
"""Initialize the OAuth for ZeusWPI"""
Expand All @@ -70,6 +71,7 @@ def init_oauth(app):
access_token_method="POST",
access_token_url="https://zauth.zeus.gent/oauth/token/",
authorize_url="https://zauth.zeus.gent/oauth/authorize/",
client_kwargs={'scope': 'roles'}
)

return oauth.create_client("zeus")
Expand Down