Skip to content
Merged
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 backend/accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ def authenticate(self, request, remote_user, shibboleth_attributes):
)

# Add initial attributes on first log in

if created:
email = self.get_email(remote_user)
if email is None or email == "":
email = f"{shibboleth_attributes['username']}@upenn.edu"
user.set_unusable_password()
user.save()
user = self.configure_user(request, user)

# Always update email

email = self.get_email(remote_user)
if email is None or email == "":
email = f"{shibboleth_attributes['username']}@upenn.edu"

old_email = Email.objects.filter(user=user, primary=True).first()

if old_email and old_email.value != email:
old_email.value = email
old_email.save()
elif not old_email:
Email.objects.create(user=user, value=email, primary=True, verified=True)

# Update fields if changed
Expand Down