Skip to content

Commit

Permalink
Merge pull request #339 from selfhoster1312/redirect-referer
Browse files Browse the repository at this point in the history
portal-api: login/logout redirect to referer when param referer_redirect is set
  • Loading branch information
alexAubin authored Aug 20, 2024
2 parents 0d7a143 + e24d56d commit 6f09185
Showing 1 changed file with 11 additions and 3 deletions.
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 @@ -381,7 +381,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 @@ -405,7 +409,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

0 comments on commit 6f09185

Please sign in to comment.