Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- returns flask_login user first, if any, and falls back on request loaders fixes #50
- Loading branch information
1 parent
aa1bc21
commit cae02a2
Showing
3 changed files
with
47 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import flask | ||
import flask_login | ||
|
||
|
||
def get_current_user(): | ||
# if flask_login has an authenticated user in session, that's who we want | ||
if flask_login.current_user and flask_login.current_user.is_authenticated: | ||
return flask_login.current_user | ||
|
||
# no user in session right now, so we need to run request loaders to see if any match | ||
user = None | ||
for loader in flask.current_app.auth_manager.request_loaders.values(): | ||
user = loader.get_authenticated_user() | ||
if user: | ||
break | ||
if not user or not user.is_authenticated: | ||
return None | ||
return user |
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