Skip to content

Commit 4d4cf93

Browse files
committed
Make password reset use username throughout and reword the reset page
so it's clear that one has to enter the account name and not just any email address associated with the account. - Legacy-Id: 11171
1 parent dedb00b commit 4d4cf93

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

ietf/ietfauth/forms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ def __init__(self, role, *args, **kwargs):
8282

8383

8484
class ResetPasswordForm(forms.Form):
85-
email = forms.EmailField(label="Your email (lowercase)")
85+
username = forms.EmailField(label="Your email (lowercase)")
8686

87-
def clean_email(self):
88-
email = self.cleaned_data["email"]
89-
if not User.objects.filter(username=email).exists():
87+
def clean_username(self):
88+
username = self.cleaned_data["username"]
89+
if not User.objects.filter(username=username).exists():
9090
raise forms.ValidationError(mark_safe("Didn't find a matching account. If you don't have an account yet, you can <a href=\"{}\">create one</a>.".format(urlreverse("create_account"))))
91-
return email
91+
return username
9292

9393

9494
class TestEmailForm(forms.Form):

ietf/ietfauth/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ def test_reset_password(self):
241241
self.assertEqual(r.status_code, 200)
242242

243243
# ask for reset, wrong username
244-
r = self.client.post(url, { 'email': "nobody@example.com" })
244+
r = self.client.post(url, { 'username': "nobody@example.com" })
245245
self.assertEqual(r.status_code, 200)
246246
q = PyQuery(r.content)
247247
self.assertTrue(len(q("form .has-error")) > 0)
248248

249249
# ask for reset
250250
empty_outbox()
251-
r = self.client.post(url, { 'email': user.username })
251+
r = self.client.post(url, { 'username': user.username })
252252
self.assertEqual(r.status_code, 200)
253253
self.assertEqual(len(outbox), 1)
254254

ietf/ietfauth/views.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,19 @@ def password_reset(request):
276276
if request.method == 'POST':
277277
form = ResetPasswordForm(request.POST)
278278
if form.is_valid():
279-
to_email = form.cleaned_data['email']
279+
username = form.cleaned_data['username']
280280

281-
auth = django.core.signing.dumps(to_email, salt="password_reset")
281+
auth = django.core.signing.dumps(username, salt="password_reset")
282282

283283
domain = Site.objects.get_current().domain
284284
subject = 'Confirm password reset at %s' % domain
285285
from_email = settings.DEFAULT_FROM_EMAIL
286+
to_email = username # form validation makes sure that this is an email address
286287

287288
send_mail(request, to_email, from_email, subject, 'registration/password_reset_email.txt', {
288289
'domain': domain,
289290
'auth': auth,
290-
'username': to_email,
291+
'username': username,
291292
'expire': settings.DAYS_TO_EXPIRE_REGISTRATION_LINK,
292293
})
293294

@@ -302,11 +303,11 @@ def password_reset(request):
302303

303304
def confirm_password_reset(request, auth):
304305
try:
305-
email = django.core.signing.loads(auth, salt="password_reset", max_age=settings.DAYS_TO_EXPIRE_REGISTRATION_LINK * 24 * 60 * 60)
306+
username = django.core.signing.loads(auth, salt="password_reset", max_age=settings.DAYS_TO_EXPIRE_REGISTRATION_LINK * 24 * 60 * 60)
306307
except django.core.signing.BadSignature:
307308
raise Http404("Invalid or expired auth")
308309

309-
user = get_object_or_404(User, username=email)
310+
user = get_object_or_404(User, username=username)
310311

311312
success = False
312313
if request.method == 'POST':
@@ -325,7 +326,7 @@ def confirm_password_reset(request, auth):
325326

326327
return render(request, 'registration/change_password.html', {
327328
'form': form,
328-
'email': email,
329+
'username': username,
329330
'success': success,
330331
})
331332

ietf/templates/registration/change_password.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>Password change successful</h1>
1818
{% else %}
1919
<h1>Change password</h1>
2020

21-
<p>You can change the password below for your user {{ email }} below.</p>
21+
<p>You can change the password below for your user {{ username }} below.</p>
2222
<form method="post">
2323
{% csrf_token %}
2424
{% bootstrap_form form %}

ietf/templates/registration/password_reset.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h1>Password reset successful</h1>
1717
{% else %}
1818
<h1>Password reset</h1>
1919

20-
<p>Please enter an email address associated with the account for which you would like to reset the password.</p>
20+
<p>Please enter the account for which you would like to reset the password.</p>
2121

2222
<form method="post">
2323
{% csrf_token %}

0 commit comments

Comments
 (0)