Skip to content

Commit 3d7b97a

Browse files
author
Matt Wright
committed
Forgot password form should not validate if user has not confirmed their email address yet. Fixes pallets-eco#298
1 parent 3a0af73 commit 3d7b97a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

flask_security/forms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ class ForgotPasswordForm(Form, UserEmailFormMixin):
175175

176176
submit = SubmitField(get_form_field_label('recover_password'))
177177

178+
def validate(self):
179+
if not super(ForgotPasswordForm, self).validate():
180+
return False
181+
if requires_confirmation(self.user):
182+
self.email.errors.append(get_message('CONFIRMATION_REQUIRED')[0])
183+
return False
184+
return True
185+
178186

179187
class PasswordlessLoginForm(Form, UserEmailFormMixin):
180188
"""The passwordless login form"""

tests/test_confirmable.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,15 @@ def test_confirmation_different_user_when_logged_in(client, get_message):
147147
response = client.get('/confirm/' + token2, follow_redirects=True)
148148
assert get_message('EMAIL_CONFIRMED') in response.data
149149
assert b'Hello lady@lp.com' in response.data
150+
151+
152+
@pytest.mark.registerable()
153+
@pytest.mark.settings(recoverable=True)
154+
def test_cannot_reset_password_when_email_is_not_confirmed(client, get_message):
155+
email = 'dude@lp.com'
156+
157+
data = dict(email=email, password='password', next='')
158+
response = client.post('/register', data=data, follow_redirects=True)
159+
160+
response = client.post('/reset', data=dict(email=email), follow_redirects=True)
161+
assert get_message('CONFIRMATION_REQUIRED') in response.data

0 commit comments

Comments
 (0)