Add proper DRF Authentication classes to user authenticated endpoint

This commit is contained in:
David Gunter 2017-06-06 12:28:06 -07:00
parent 1cc46e7b24
commit a2bc1b5196
2 changed files with 5 additions and 2 deletions

View File

@ -498,6 +498,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
user = get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS)
self._login()
self.token = self.response.json['key']
self.get(self.user_authenticated_status_url, status_code=200)
self.assertTrue(self.response.json['authenticated'])

View File

@ -14,6 +14,7 @@ from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from .app_settings import (
TokenSerializer, UserDetailsSerializer, LoginSerializer,
@ -160,11 +161,11 @@ class UserAuthenticationStatusView(APIView):
Returns True/False indicator for if user is authenticated.
"""
authentication_classes = ()
authentication_classes = (TokenAuthentication,)
permission_classes = ()
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(
{"authenticated": True}, status=status.HTTP_200_OK
)
@ -173,6 +174,7 @@ class UserAuthenticationStatusView(APIView):
{"authenticated": False}, status=status.HTTP_401_UNAUTHORIZED
)
class PasswordResetView(GenericAPIView):
"""
Calls Django Auth PasswordResetForm save method.