mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-20 02:52:11 +00:00
Add /admin/bye route for control panel token invalidation
This commit is contained in:
parent
aaf46df039
commit
745f2de25f
@ -145,6 +145,11 @@ class KeyAuthService:
|
||||
# Check whether the provided token in request cookie matches the one we stored for the user.
|
||||
return self.check_user_token(email, request.cookies.get("miab-cp-token"), request, env)
|
||||
|
||||
def remove_user_token(self, email, request, env):
|
||||
# Remove the user's token from the in-memory session database.
|
||||
# Returns the invalidated token if exists.
|
||||
return KeyAuthService.__token_dict.pop(email)
|
||||
|
||||
def create_user_key(self, email, env):
|
||||
# Create a user API key, which is a shared secret that we can re-generate from
|
||||
# static information in our database. The shared secret contains the user's
|
||||
|
@ -174,6 +174,19 @@ def me():
|
||||
# Return.
|
||||
return resp
|
||||
|
||||
|
||||
@app.route('/bye')
|
||||
def bye():
|
||||
try:
|
||||
email, _, _ = auth_service.authenticate(request, env)
|
||||
auth_service.remove_user_token(email, request, env)
|
||||
except ValueError:
|
||||
pass # Unauthorized users can logout too, simply do nothing.
|
||||
finally:
|
||||
resp = Response()
|
||||
resp.set_cookie("miab-cp-token", expires=0) # Removes the token cookie
|
||||
return resp
|
||||
|
||||
# MAIL
|
||||
|
||||
@app.route('/mail/users')
|
||||
|
Loading…
Reference in New Issue
Block a user