diff --git a/ietf/ietfauth/tests.py b/ietf/ietfauth/tests.py index 6a85c6eb13..86f2051581 100644 --- a/ietf/ietfauth/tests.py +++ b/ietf/ietfauth/tests.py @@ -527,6 +527,24 @@ def test_reset_password_without_username(self): self.assertIn(secondary_address, to) self.assertNotIn(inactive_secondary_address, to) + def test_reset_password_without_user(self): + """Reset password using email address for person without a user account""" + url = urlreverse('ietf.ietfauth.views.password_reset') + email = EmailFactory() + person = email.person + # Remove the user object from the person to get a Email/Person without User: + person.user = None + person.save() + # Remove the remaining User record, since reset_password looks for that by username: + User.objects.filter(username__iexact=email.address).delete() + empty_outbox() + r = self.client.post(url, { 'username': email.address }) + self.assertEqual(len(outbox), 1) + lastReceivedEmail = outbox[-1] + self.assertIn(email.address, lastReceivedEmail.get('To')) + self.assertTrue(lastReceivedEmail.get('Subject').startswith('Confirm registration at')) + self.assertContains(r, 'We have sent you an email with instructions', status_code=200) + def test_review_overview(self): review_req = ReviewRequestFactory() assignment = ReviewAssignmentFactory(review_request=review_req,reviewer=EmailFactory(person__user__username='reviewer')) diff --git a/ietf/ietfauth/views.py b/ietf/ietfauth/views.py index 61c7b929b1..d40118834b 100644 --- a/ietf/ietfauth/views.py +++ b/ietf/ietfauth/views.py @@ -491,8 +491,11 @@ def password_reset(request): if not user: # try to find user ID from the email address email = Email.objects.filter(address=submitted_username).first() - if email and email.person and email.person.user: - user = email.person.user + if email and email.person: + if email.person.user: + user = email.person.user + else: + send_account_creation_email(request, email.email_address()) if user and user.person.email_set.filter(active=True).exists(): data = {