-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix breaking change (caused by flask_login) on Geonature password cha…
…nge route (#191) fix breaking change provoked by flask_login on the password change route
- Loading branch information
1 parent
f2a1d5e
commit 131c620
Showing
3 changed files
with
44 additions
and
6 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 flask import current_app, Response, request, redirect, url_for | ||
from urllib.parse import urlencode | ||
from werkzeug.exceptions import Unauthorized | ||
|
||
|
||
# Unauthorized means disconnected | ||
# (logged but not allowed to perform an action = Forbidden) | ||
|
||
|
||
def handle_unauthenticated_request(): | ||
""" | ||
To avoid returning the login page html when a route is used by geonature API | ||
this function overrides `LoginManager.unauthorized()` from `flask-login` . | ||
Returns | ||
------- | ||
flask.Response | ||
response | ||
""" | ||
if "application/json" in request.headers.get("Content-Type", ""): | ||
raise Unauthorized | ||
else: | ||
return redirect(url_for("login.login", next=request.path)) |