Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user_logged_in instead of update_last_login #752

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions rest_framework_simplejwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from django.conf import settings
from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth.models import AbstractBaseUser, update_last_login
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.signals import user_logged_in
from django.utils.translation import gettext_lazy as _
from rest_framework import exceptions, serializers
from rest_framework.exceptions import ValidationError
Expand Down Expand Up @@ -78,7 +79,12 @@ def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
data["access"] = str(refresh.access_token)

if api_settings.UPDATE_LAST_LOGIN:
update_last_login(None, self.user)
user_logged_in.send(
sender=self.__class__,
user=self.user,
data=data,
request=self.context.get("request"),
)

return data

Expand All @@ -94,7 +100,12 @@ def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
data["token"] = str(token)

if api_settings.UPDATE_LAST_LOGIN:
update_last_login(None, self.user)
user_logged_in.send(
sender=self.__class__,
user=self.user,
data=data,
request=self.context.get("request"),
)

return data

Expand Down