Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

portal-api: login/logout redirect to referer when param referer_redirect is set #339

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
14 changes: 11 additions & 3 deletions moulinette/interfaces/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from gevent.queue import Queue
from geventwebsocket import WebSocketError

from bottle import request, response, Bottle, HTTPResponse, FileUpload
from bottle import redirect, request, response, Bottle, HTTPResponse, FileUpload
from bottle import abort

from moulinette import m18n, Moulinette
Expand Down Expand Up @@ -380,7 +380,11 @@ def login(self):
raise HTTPResponse(e.strerror, 401)
else:
authenticator.set_session_cookie(auth_infos)
return m18n.g("logged_in")
referer = request.get_header("Referer")
if "referer_redirect" in request.params and referer:
redirect(referer)
else:
return m18n.g("logged_in")

# This is called before each time a route is going to be processed
def authenticate(self, authenticator):
Expand All @@ -404,7 +408,11 @@ def logout(self):
else:
# Delete cookie and clean the session
authenticator.delete_session_cookie()
return m18n.g("logged_out")
referer = request.get_header("Referer")
if "referer_redirect" in request.params and referer:
redirect(referer)
else:
return m18n.g("logged_in")

def messages(self):
"""Listen to the messages WebSocket stream
Expand Down
Loading