1 | diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
|
---|
2 | index 7473279..3dcbd84 100644
|
---|
3 | --- a/django/contrib/auth/forms.py
|
---|
4 | +++ b/django/contrib/auth/forms.py
|
---|
5 | @@ -109,10 +109,13 @@ class PasswordResetForm(forms.Form):
|
---|
6 |
|
---|
7 | def clean_email(self):
|
---|
8 | """
|
---|
9 | - Validates that a user exists with the given e-mail address.
|
---|
10 | + Validates that an active user exists with the given e-mail address.
|
---|
11 | """
|
---|
12 | email = self.cleaned_data["email"]
|
---|
13 | - self.users_cache = User.objects.filter(email__iexact=email)
|
---|
14 | + self.users_cache = User.objects.filter(
|
---|
15 | + email__iexact=email,
|
---|
16 | + is_active=True
|
---|
17 | + )
|
---|
18 | if len(self.users_cache) == 0:
|
---|
19 | raise forms.ValidationError(_("That e-mail address doesn't have an associated user account. Are you sure you've registered?"))
|
---|
20 | return email
|
---|
21 | diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
|
---|
22 | index 5aa49e0..6f9e01d 100644
|
---|
23 | --- a/django/contrib/auth/tests/forms.py
|
---|
24 | +++ b/django/contrib/auth/tests/forms.py
|
---|
25 | @@ -219,6 +219,15 @@ class PasswordResetFormTest(TestCase):
|
---|
26 |
|
---|
27 | fixtures = ['authtestdata.json']
|
---|
28 |
|
---|
29 | + def create_dummy_user(self):
|
---|
30 | + """creates a user and returns a tuple
|
---|
31 | + (user_object, username, email)
|
---|
32 | + """
|
---|
33 | + username = 'jsmith'
|
---|
34 | + email = 'jsmith@example.com'
|
---|
35 | + user = User.objects.create_user(username, email, 'test123')
|
---|
36 | + return (user, username, email)
|
---|
37 | +
|
---|
38 | def test_invalid_email(self):
|
---|
39 | data = {'email':'not valid'}
|
---|
40 | form = PasswordResetForm(data)
|
---|
41 | @@ -236,11 +245,11 @@ class PasswordResetFormTest(TestCase):
|
---|
42 |
|
---|
43 | def test_cleaned_data(self):
|
---|
44 | # Regression test
|
---|
45 | - user = User.objects.create_user("jsmith3", "jsmith3@example.com", "test123")
|
---|
46 | - data = {'email':'jsmith3@example.com'}
|
---|
47 | + (user, username, email) = self.create_dummy_user()
|
---|
48 | + data = {'email': email}
|
---|
49 | form = PasswordResetForm(data)
|
---|
50 | self.assertTrue(form.is_valid())
|
---|
51 | - self.assertEqual(form.cleaned_data['email'], u'jsmith3@example.com')
|
---|
52 | + self.assertEqual(form.cleaned_data['email'], email)
|
---|
53 |
|
---|
54 |
|
---|
55 | def test_bug_5605(self):
|
---|
56 | @@ -250,3 +259,12 @@ class PasswordResetFormTest(TestCase):
|
---|
57 | self.assertEqual(user.email, 'tesT@example.com')
|
---|
58 | user = User.objects.create_user('forms_test3', 'tesT', 'test')
|
---|
59 | self.assertEqual(user.email, 'tesT')
|
---|
60 | +
|
---|
61 | + def test_inactive_user(self):
|
---|
62 | + #tests that inactive user cannot
|
---|
63 | + #receive password reset email
|
---|
64 | + (user, username, email) = self.create_dummy_user()
|
---|
65 | + user.is_active = False
|
---|
66 | + user.save()
|
---|
67 | + form = PasswordResetForm({'email': email})
|
---|
68 | + self.assertFalse(form.is_valid())
|
---|