mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-07-22 13:39:45 +03:00
Add proper DRF Authentication classes to user authenticated endpoint
This commit is contained in:
parent
1cc46e7b24
commit
a2bc1b5196
|
@ -498,6 +498,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
||||||
user = get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS)
|
user = get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS)
|
||||||
|
|
||||||
self._login()
|
self._login()
|
||||||
|
self.token = self.response.json['key']
|
||||||
|
|
||||||
self.get(self.user_authenticated_status_url, status_code=200)
|
self.get(self.user_authenticated_status_url, status_code=200)
|
||||||
self.assertTrue(self.response.json['authenticated'])
|
self.assertTrue(self.response.json['authenticated'])
|
||||||
|
|
|
@ -14,6 +14,7 @@ from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView
|
from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView
|
||||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||||
|
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
|
||||||
|
|
||||||
from .app_settings import (
|
from .app_settings import (
|
||||||
TokenSerializer, UserDetailsSerializer, LoginSerializer,
|
TokenSerializer, UserDetailsSerializer, LoginSerializer,
|
||||||
|
@ -160,11 +161,11 @@ class UserAuthenticationStatusView(APIView):
|
||||||
|
|
||||||
Returns True/False indicator for if user is authenticated.
|
Returns True/False indicator for if user is authenticated.
|
||||||
"""
|
"""
|
||||||
authentication_classes = ()
|
authentication_classes = (TokenAuthentication,)
|
||||||
permission_classes = ()
|
permission_classes = ()
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if hasattr(request, "user") and request.user.is_authenticated:
|
if hasattr(self.request, "user") and self.request.user.is_authenticated:
|
||||||
return Response(
|
return Response(
|
||||||
{"authenticated": True}, status=status.HTTP_200_OK
|
{"authenticated": True}, status=status.HTTP_200_OK
|
||||||
)
|
)
|
||||||
|
@ -173,6 +174,7 @@ class UserAuthenticationStatusView(APIView):
|
||||||
{"authenticated": False}, status=status.HTTP_401_UNAUTHORIZED
|
{"authenticated": False}, status=status.HTTP_401_UNAUTHORIZED
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PasswordResetView(GenericAPIView):
|
class PasswordResetView(GenericAPIView):
|
||||||
"""
|
"""
|
||||||
Calls Django Auth PasswordResetForm save method.
|
Calls Django Auth PasswordResetForm save method.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user