konova/konova/views/logout.py
mpeltriaux 7b5c1f0d97 # Hotfix
* fixes bug where anonymous user trying to logout would throw error
2024-12-23 13:41:25 +01:00

37 lines
911 B
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22
"""
from django.contrib.auth import logout
from django.http import HttpRequest
from django.shortcuts import redirect
from django.views import View
from konova.sub_settings.sso_settings import SSO_SERVER_BASE
class LogoutView(View):
def get(self, request: HttpRequest):
"""
Logout route for ending the session manually.
Args:
request (HttpRequest): The used request object
Returns:
A redirect
"""
user = request.user
try:
oauth_token = user.oauth_token
if oauth_token:
oauth_token.revoke()
except AttributeError:
pass
logout(request)
return redirect(SSO_SERVER_BASE)