Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Forgot password form should not validate if user has not confirmed th…
Browse files Browse the repository at this point in the history
…eir email address yet. Fixes #298
  • Loading branch information
Matt Wright committed Sep 17, 2014
1 parent 3a0af73 commit 3d7b97a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flask_security/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ class ForgotPasswordForm(Form, UserEmailFormMixin):

submit = SubmitField(get_form_field_label('recover_password'))

def validate(self):
if not super(ForgotPasswordForm, self).validate():
return False
if requires_confirmation(self.user):
self.email.errors.append(get_message('CONFIRMATION_REQUIRED')[0])
return False
return True


class PasswordlessLoginForm(Form, UserEmailFormMixin):
"""The passwordless login form"""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_confirmable.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ def test_confirmation_different_user_when_logged_in(client, get_message):
response = client.get('/confirm/' + token2, follow_redirects=True)
assert get_message('EMAIL_CONFIRMED') in response.data
assert b'Hello lady@lp.com' in response.data


@pytest.mark.registerable()
@pytest.mark.settings(recoverable=True)
def test_cannot_reset_password_when_email_is_not_confirmed(client, get_message):
email = 'dude@lp.com'

data = dict(email=email, password='password', next='')
response = client.post('/register', data=data, follow_redirects=True)

response = client.post('/reset', data=dict(email=email), follow_redirects=True)
assert get_message('CONFIRMATION_REQUIRED') in response.data

0 comments on commit 3d7b97a

Please sign in to comment.