Skip to content

Commit ebf6a92

Browse files
authored
Merge pull request #288 from Tivix/logout_on_get
Logout on get
2 parents 667e70c + cef8d67 commit ebf6a92

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

docs/api_endpoints.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Basic
1313

1414
- /rest-auth/logout/ (POST, GET)
1515

16-
.. note:: ``ACCOUNT_LOGOUT_ON_GET = True`` to allow logout using GET (this is the exact same conf from allauth)
17-
1816
- token
1917

18+
.. note:: ``ACCOUNT_LOGOUT_ON_GET = True`` to allow logout using GET - this is the exact same configuration from allauth. NOT recommended, see: http://django-allauth.readthedocs.io/en/latest/views.html#logout
19+
2020
- /rest-auth/password/reset/ (POST)
2121

2222
- email
@@ -37,7 +37,6 @@ Basic
3737
- old_password
3838
- token
3939

40-
4140
.. note:: ``OLD_PASSWORD_FIELD_ENABLED = True`` to use old_password.
4241
.. note:: ``LOGOUT_ON_PASSWORD_CHANGE = False`` to keep the user logged in after password change
4342

rest_auth/views.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView
1313
from rest_framework.permissions import IsAuthenticated, AllowAny
1414

15-
if 'allauth' in settings.INSTALLED_APPS:
16-
from allauth.account import app_settings as allauth_settings
17-
1815
from .app_settings import (
1916
TokenSerializer, UserDetailsSerializer, LoginSerializer,
2017
PasswordResetSerializer, PasswordResetConfirmSerializer,
@@ -94,13 +91,10 @@ class LogoutView(APIView):
9491
permission_classes = (AllowAny,)
9592

9693
def get(self, request, *args, **kwargs):
97-
try:
98-
if allauth_settings.LOGOUT_ON_GET:
99-
response = self.logout(request)
100-
else:
101-
response = self.http_method_not_allowed(request, *args, **kwargs)
102-
except Exception as exc:
103-
response = self.handle_exception(exc)
94+
if getattr(settings, 'ACCOUNT_LOGOUT_ON_GET', False):
95+
response = self.logout(request)
96+
else:
97+
response = self.http_method_not_allowed(request, *args, **kwargs)
10498

10599
return self.finalize_response(request, response, *args, **kwargs)
106100

0 commit comments

Comments
 (0)