Skip to content

Commit 6bad7bc

Browse files
committed
Fixing tests | removed dep
1 parent 4f6277d commit 6bad7bc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

core/users/views.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from pydash import get
1212
from rest_framework import mixins, status
1313
from rest_framework.authtoken.serializers import AuthTokenSerializer
14-
from rest_framework.authtoken.views import ObtainAuthToken
1514
from rest_framework.exceptions import PermissionDenied
1615
from rest_framework.generics import RetrieveAPIView, UpdateAPIView, DestroyAPIView, RetrieveUpdateDestroyAPIView, \
1716
ListAPIView
@@ -126,8 +125,9 @@ def get(request):
126125
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
127126

128127

129-
class TokenAuthenticationView(ObtainAuthToken):
130-
"""Implementation of ObtainAuthToken with last_login update"""
128+
class TokenAuthenticationView(APIView):
129+
"""Authenticate a user and return their token without DRF's deprecated schema dependency."""
130+
permission_classes = (AllowAny,)
131131

132132
def get_throttles(self):
133133
return ThrottleUtil.get_throttles_by_user_plan(self.request.user)
@@ -151,6 +151,12 @@ def post(self, request, *args, **kwargs):
151151
raise Http400(
152152
{'error': ["Single Sign On is enabled in this environment. Cannot login via API directly."]})
153153

154+
serializer = AuthTokenSerializer(
155+
data=request.data,
156+
context={'request': request},
157+
)
158+
serializer.is_valid(raise_exception=True)
159+
154160
user = UserProfile.objects.filter(username=request.data.get('username')).first()
155161

156162
if not user or not user.check_password(request.data.get('password')):
@@ -173,7 +179,7 @@ def post(self, request, *args, **kwargs):
173179
}, status=status.HTTP_401_UNAUTHORIZED
174180
)
175181

176-
result = super().post(request, *args, **kwargs)
182+
result = Response({'token': user.get_token()})
177183

178184
try:
179185
update_last_login(None, user)

0 commit comments

Comments
 (0)