Skip to content

Commit b0c7641

Browse files
authored
feat: Allow password reset with non username email address (ietf-tools#5419)
This change allows password reset with any email address associated with the account. The password reset will only be sent to the active email addresses associated with the account. Fixes ietf-tools#5057
1 parent 52a1069 commit b0c7641

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

ietf/ietfauth/tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,21 @@ def test_reset_password_address_handling(self):
563563
self.assertIn(active_address, to)
564564
self.assertNotIn(person.user.username, to)
565565

566+
def test_reset_password_without_username(self):
567+
"""Reset password using non-username email address"""
568+
url = urlreverse('ietf.ietfauth.views.password_reset')
569+
person = PersonFactory()
570+
secondary_address = EmailFactory(person=person).address
571+
inactive_secondary_address = EmailFactory(person=person, active=False).address
572+
empty_outbox()
573+
r = self.client.post(url, { 'username': secondary_address})
574+
self.assertContains(r, 'We have sent you an email with instructions', status_code=200)
575+
self.assertEqual(len(outbox), 1)
576+
to = outbox[0].get('To')
577+
self.assertIn(person.user.username, to)
578+
self.assertIn(secondary_address, to)
579+
self.assertNotIn(inactive_secondary_address, to)
580+
566581
def test_review_overview(self):
567582
review_req = ReviewRequestFactory()
568583
assignment = ReviewAssignmentFactory(review_request=review_req,reviewer=EmailFactory(person__user__username='reviewer'))

ietf/ietfauth/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ def password_reset(request):
463463
# We still report that the action succeeded, so we're not leaking the existence of user
464464
# email addresses.
465465
user = User.objects.filter(username__iexact=submitted_username, person__isnull=False).first()
466+
if not user:
467+
# try to find user ID from the email address
468+
email = Email.objects.filter(address=submitted_username).first()
469+
if email and email.person and email.person.user:
470+
user = email.person.user
471+
466472
if user and user.person.email_set.filter(active=True).exists():
467473
data = {
468474
'username': user.username,

0 commit comments

Comments
 (0)