mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-10 19:26:35 +03:00
Merge pull request #345 from gbezyuk/master
LoginView.get_response modified in order to respect rest_framework_jwt.JWT_AUTH_COOKIE setting
This commit is contained in:
commit
bb3b082895
|
@ -84,7 +84,17 @@ class LoginView(GenericAPIView):
|
|||
serializer = serializer_class(instance=self.token,
|
||||
context={'request': self.request})
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
response = Response(serializer.data, status=status.HTTP_200_OK)
|
||||
if getattr(settings, 'REST_USE_JWT', False):
|
||||
from rest_framework_jwt.settings import api_settings as jwt_settings
|
||||
if jwt_settings.JWT_AUTH_COOKIE:
|
||||
from datetime import datetime
|
||||
expiration = (datetime.utcnow() + jwt_settings.JWT_EXPIRATION_DELTA)
|
||||
response.set_cookie(jwt_settings.JWT_AUTH_COOKIE,
|
||||
self.token,
|
||||
expires=expiration,
|
||||
httponly=True)
|
||||
return response
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.request = request
|
||||
|
@ -124,8 +134,13 @@ class LogoutView(APIView):
|
|||
if getattr(settings, 'REST_SESSION_LOGIN', True):
|
||||
django_logout(request)
|
||||
|
||||
return Response({"detail": _("Successfully logged out.")},
|
||||
status=status.HTTP_200_OK)
|
||||
response = Response({"detail": _("Successfully logged out.")},
|
||||
status=status.HTTP_200_OK)
|
||||
if getattr(settings, 'REST_USE_JWT', False):
|
||||
from rest_framework_jwt.settings import api_settings as jwt_settings
|
||||
if jwt_settings.JWT_AUTH_COOKIE:
|
||||
response.delete_cookie(jwt_settings.JWT_AUTH_COOKIE)
|
||||
return response
|
||||
|
||||
|
||||
class UserDetailsView(RetrieveUpdateAPIView):
|
||||
|
|
Loading…
Reference in New Issue
Block a user