Skip to content

Commit

Permalink
Add last login for user purging (#54)
Browse files Browse the repository at this point in the history
* add last login for stale account purge

* Update serializers.py

* Update models.py

* Update models.py

* Update serializers.py

---------

Co-authored-by: Jonathan Loh <[email protected]>
Co-authored-by: John Wong <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2025
1 parent c01cffe commit 636cffb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/treeckle/authentication/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import requests

from django.utils.timezone import now

from rest_framework import serializers, exceptions

from rest_framework_simplejwt.serializers import TokenRefreshSerializer
Expand Down Expand Up @@ -179,6 +181,9 @@ def authenticate(self, auth_data: AuthenticationData) -> dict:
if authenticated_user is None:
self.raise_invalid_user()

authenticated_user.last_login = now()
authenticated_user.save()

return get_authenticated_data(user=authenticated_user)


Expand Down
18 changes: 18 additions & 0 deletions backend/treeckle/users/migrations/0018_user_last_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2025-01-21 13:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0017_alter_user_profile_image'),
]

operations = [
migrations.AddField(
model_name='user',
name='last_login',
field=models.DateTimeField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions backend/treeckle/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class User(TimestampedModel):
profile_image = models.ForeignKey(
Image, null=True, blank=True, on_delete=models.SET_NULL
)
last_login = models.DateTimeField(null=True, blank=True)

def __str__(self):
return f"{self.name} | {self.email} ({self.organization})"
Expand Down

0 comments on commit 636cffb

Please sign in to comment.