Skip to content

Commit 82e9731

Browse files
authored
Update emails on every login (#137)
* update emails on login * check old email and update that
1 parent 8545148 commit 82e9731

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

backend/accounts/backends.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@ def authenticate(self, request, remote_user, shibboleth_attributes):
4242
)
4343

4444
# Add initial attributes on first log in
45+
4546
if created:
46-
email = self.get_email(remote_user)
47-
if email is None or email == "":
48-
email = f"{shibboleth_attributes['username']}@upenn.edu"
4947
user.set_unusable_password()
5048
user.save()
5149
user = self.configure_user(request, user)
50+
51+
# Always update email
52+
53+
email = self.get_email(remote_user)
54+
if email is None or email == "":
55+
email = f"{shibboleth_attributes['username']}@upenn.edu"
56+
57+
old_email = Email.objects.filter(user=user, primary=True).first()
58+
59+
if old_email and old_email.value != email:
60+
old_email.value = email
61+
old_email.save()
62+
elif not old_email:
5263
Email.objects.create(user=user, value=email, primary=True, verified=True)
5364

5465
# Update fields if changed

0 commit comments

Comments
 (0)