Resolve Last Login Issue

Whenever someone want to login using rest api and got token his last login not store. I resolve this issue
This commit is contained in:
Ujjwal Kar 2022-02-24 22:16:20 +05:30 committed by GitHub
parent efc7c1d664
commit 896af5661d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ from rest_framework.response import Response
from rest_framework.schemas import ManualSchema from rest_framework.schemas import ManualSchema
from rest_framework.schemas import coreapi as coreapi_schema from rest_framework.schemas import coreapi as coreapi_schema
from rest_framework.views import APIView from rest_framework.views import APIView
from django.contrib.auth import authenticate, login
class ObtainAuthToken(APIView): class ObtainAuthToken(APIView):
@ -52,6 +53,11 @@ class ObtainAuthToken(APIView):
return self.serializer_class(*args, **kwargs) return self.serializer_class(*args, **kwargs)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
username = request.data["username"]
password = request.data["password"]
usr = authenticate(request, username=username, password=password)
if usr is not None:
login(request, usr)
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)
user = serializer.validated_data['user'] user = serializer.validated_data['user']