forked from numerique-gouv/b3desk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: keep user logged in on error pages
The `user` var was not passed to the error pages templates, so user would appear logged out on 404 or 500 error pages for instance.
- Loading branch information
Showing
3 changed files
with
45 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from b3desk.models.users import get_or_create_user | ||
from flask import session | ||
from flask_pyoidc.user_session import UserSession | ||
|
||
|
||
def get_current_user(): | ||
user_session = UserSession(session) | ||
info = user_session.userinfo | ||
return get_or_create_user(info) | ||
|
||
|
||
def has_user_session(): | ||
user_session = UserSession(dict(session), "default") | ||
return user_session.is_authenticated() | ||
|
||
|
||
def get_authenticated_attendee_fullname(): | ||
attendee_session = UserSession(session) | ||
attendee_info = attendee_session.userinfo | ||
given_name = attendee_info.get("given_name", "") | ||
family_name = attendee_info.get("family_name", "") | ||
fullname = f"{given_name} {family_name}".strip() | ||
return fullname |