mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
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:
parent
efc7c1d664
commit
896af5661d
|
@ -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']
|
||||||
|
|
Loading…
Reference in New Issue
Block a user