Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Send create user email for password resets where we have an email and person, but no user. #7729

Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions ietf/ietfauth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 password reset"))
self.assertContains(r, "Your password reset request has been successfully received", status_code=200)

def test_review_overview(self):
review_req = ReviewRequestFactory()
assignment = ReviewAssignmentFactory(review_request=review_req,reviewer=EmailFactory(person__user__username='reviewer'))
Expand Down
16 changes: 13 additions & 3 deletions ietf/ietfauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,19 @@ 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:
jennifer-richards marked this conversation as resolved.
Show resolved Hide resolved
if email.person.user:
user = email.person.user
else:
# Create a User record with this (conditioned by way of Email) username
# Don't bother setting the name or email fields on User - rely on the
# Person pointer.
user = User.objects.create(
username=email.address.lower(),
is_active=True,
rjsparks marked this conversation as resolved.
Show resolved Hide resolved
)
email.person.user = user
email.person.save()
if user and user.person.email_set.filter(active=True).exists():
data = {
'username': user.username,
Expand Down
Loading