Skip to content

Commit

Permalink
Correctly migrate users with bad last access (refs #458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Almad committed Mar 2, 2024
1 parent 9fbc68d commit ca23c6c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ddcz/users.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from django.contrib.auth import logout
from django.contrib.auth.models import User

Expand All @@ -11,6 +13,9 @@ def migrate_user(profile, password=""):
If the password is not given (because i.e. migration is happening on a password reset field),
it's set to unusable password and password reset is required before logging in.
"""
if not profile.last_login:
profile.last_login = datetime.now()

user = User.objects.create_user(
id=profile.id,
username=profile.nick,
Expand All @@ -26,7 +31,6 @@ def migrate_user(profile, password=""):
user.save()

# TODO: Presumably, we could fix more things during migration...like foreign keys.

return user


Expand Down

0 comments on commit ca23c6c

Please sign in to comment.