From b0e1eb5aaa3baf04ecba0bdd22abf06ea95f7779 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Tue, 8 Apr 2025 08:33:46 +0200 Subject: [PATCH] fix: minor bugfixes --- auth_app/models.py | 2 +- auth_app/views.py | 13 ++++++------- join/settings.py | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/auth_app/models.py b/auth_app/models.py index b5c8a21..08a580e 100644 --- a/auth_app/models.py +++ b/auth_app/models.py @@ -29,6 +29,6 @@ class ExpiringTokenAuthentication(TokenAuthentication): if token.is_expired(): token.delete() - raise AuthenticationFailed({"error": "No active session or token already expired"}) + raise AuthenticationFailed({"error": "Token expired."}) return (token.user, token) \ No newline at end of file diff --git a/auth_app/views.py b/auth_app/views.py index 37539c3..2fae7b6 100644 --- a/auth_app/views.py +++ b/auth_app/views.py @@ -12,24 +12,23 @@ from user_app.serializers import UserSerializer from django.contrib.auth.tokens import default_token_generator from .services import create_password_reset_link, send_password_reset_email, verify_password_reset_token, set_user_password - User = get_user_model() class LoginView(APIView): serializer_class = LoginSerializer def _create_token_response(self, user): + now = timezone.now() token, created = ExpiringToken.objects.get_or_create(user=user) - if not created and token.is_expired(): + if token.is_expired(): token.delete() token = ExpiringToken.objects.create(user=user) - if created or not token.expires_at: - token.expires_at = timezone.now() + TOKEN_EXPIRATION_TIME - token.save() - - user.last_login = timezone.now() + token.expires_at = now + TOKEN_EXPIRATION_TIME + token.save() + + user.last_login = now user.save(update_fields=['last_login']) return Response({'token': token.key, 'user_id': user.id}, status=status.HTTP_200_OK) diff --git a/join/settings.py b/join/settings.py index 091dd95..ba56f79 100644 --- a/join/settings.py +++ b/join/settings.py @@ -170,7 +170,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' AUTH_TOKEN_MODEL = 'auth_app.ExpiringToken' -TOKEN_EXPIRATION_TIME = timedelta(hours=4) +TOKEN_EXPIRATION_TIME = timedelta(hours=24) # Authentication