From 0ab88ce7542733c1c330de80da35f13906a819c6 Mon Sep 17 00:00:00 2001 From: xinwen Date: Wed, 7 Apr 2021 10:29:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=BF=E9=97=AE=20tokens=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/serializers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/authentication/serializers.py b/apps/authentication/serializers.py index 528cc7cf9..c86b48039 100644 --- a/apps/authentication/serializers.py +++ b/apps/authentication/serializers.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # +from django.utils import timezone from rest_framework import serializers from common.utils import get_object_or_none @@ -44,6 +45,10 @@ class BearerTokenSerializer(serializers.Serializer): def get_keyword(obj): return 'Bearer' + def update_last_login(self, user): + user.last_login = timezone.now() + user.save(update_fields=['last_login']) + def create(self, validated_data): request = self.context.get('request') if request.user and not request.user.is_anonymous: @@ -56,6 +61,8 @@ class BearerTokenSerializer(serializers.Serializer): "user id {} not exist".format(user_id) ) token, date_expired = user.create_bearer_token(request) + self.update_last_login(user) + instance = { "token": token, "date_expired": date_expired,