refactored logout endpoint
This commit is contained in:
parent
de0a1d6358
commit
6d95349a52
|
|
@ -1,20 +1,18 @@
|
||||||
"""Common serializer for application authorization"""
|
"""Common serializer for application authorization"""
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
from django.contrib.auth import password_validation as password_validators
|
from django.contrib.auth import password_validation as password_validators
|
||||||
|
from django.db.models import Q
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework import validators as rest_validators
|
from rest_framework import validators as rest_validators
|
||||||
from django.contrib.auth import authenticate
|
# JWT
|
||||||
from django.db.models import Q
|
from rest_framework_simplejwt import tokens
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from account import models as account_models
|
from account import models as account_models
|
||||||
from authorization.models import Application, BlacklistedAccessToken
|
from authorization.models import Application, BlacklistedAccessToken
|
||||||
from utils import exceptions as utils_exceptions
|
from utils import exceptions as utils_exceptions
|
||||||
from utils import methods as utils_methods
|
from utils import methods as utils_methods
|
||||||
|
|
||||||
# JWT
|
|
||||||
from rest_framework_simplejwt import tokens
|
|
||||||
|
|
||||||
|
|
||||||
JWT_SETTINGS = settings.SIMPLE_JWT
|
JWT_SETTINGS = settings.SIMPLE_JWT
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -202,8 +200,8 @@ class LogoutSerializer(serializers.ModelSerializer):
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
"""Override validated data"""
|
"""Override validated data"""
|
||||||
request = self.context.get('request')
|
request = self.context.get('request')
|
||||||
token = request._request.headers.get('Authorization') \
|
token = request.headers.get('Authorization') \
|
||||||
.split(' ')[::-1][0]
|
.split(' ')[::-1][0]
|
||||||
access_token = tokens.AccessToken(token)
|
access_token = tokens.AccessToken(token)
|
||||||
# Prepare validated data
|
# Prepare validated data
|
||||||
attrs['user'] = request.user
|
attrs['user'] = request.user
|
||||||
|
|
|
||||||
|
|
@ -23,27 +23,18 @@ urlpatterns_social_django = [
|
||||||
urlpatterns_oauth2 = [
|
urlpatterns_oauth2 = [
|
||||||
path('oauth2/signup/facebook/', views.OAuth2SignUpView.as_view(),
|
path('oauth2/signup/facebook/', views.OAuth2SignUpView.as_view(),
|
||||||
name='oauth2-signup-facebook'),
|
name='oauth2-signup-facebook'),
|
||||||
# for admin sign in page
|
# for sign up via facebook
|
||||||
path('oauth2/token/', drf_social_oauth2_views .TokenView.as_view(),
|
path('oauth2/token/', drf_social_oauth2_views .TokenView.as_view(), name="token"),
|
||||||
name="token"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns_jwt = [
|
urlpatterns_jwt = [
|
||||||
path('signup/', views.SignUpView.as_view(),
|
path('signup/', views.SignUpView.as_view(), name='signup'),
|
||||||
name='signup'),
|
path('login/', views.LoginByUsernameOrEmailView.as_view(), name='login'),
|
||||||
# sign in
|
path('refresh-token/', views.RefreshTokenView.as_view(), name="refresh-token"),
|
||||||
path('login/', views.LoginByUsernameOrEmailView.as_view(),
|
path('logout/', views.LogoutView.as_view(), name="logout"),
|
||||||
name='login'),
|
|
||||||
# refresh token
|
|
||||||
path('refresh-token/', views.RefreshTokenView.as_view(),
|
|
||||||
name="refresh-token"),
|
|
||||||
# logout
|
|
||||||
path('logout/', views.LogoutView.as_view(),
|
|
||||||
name="logout"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = urlpatterns_jwt + \
|
urlpatterns = urlpatterns_jwt + \
|
||||||
urlpatterns_oauth2 + \
|
urlpatterns_oauth2 + \
|
||||||
urlpatterns_social_django # for social oauth2
|
urlpatterns_social_django # for social oauth2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,9 +210,9 @@ class LogoutView(JWTGenericViewMixin):
|
||||||
"""Logout user"""
|
"""Logout user"""
|
||||||
serializer_class = serializers.LogoutSerializer
|
serializer_class = serializers.LogoutSerializer
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""Override create method"""
|
"""Override create method"""
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return Response(status=status.HTTP_200_OK)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user