Skip to content

Commit

Permalink
No confirmation mail if user has already confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar committed Jun 14, 2017
1 parent 37f9ae0 commit b4e6c55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions flask_security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ def confirm_email(token):
if not user or invalid:
invalid = True
do_flash(*get_message('INVALID_CONFIRMATION_TOKEN'))
if expired:

already_confirmed = user is not None and user.confirmed_at is not None

if expired and not already_confirmed:
send_confirmation_instructions(user)
do_flash(*get_message('CONFIRMATION_EXPIRED', email=user.email,
within=_security.confirm_email_within))
if invalid or expired:
if invalid or (expired and not already_confirmed):
return redirect(get_url(_security.confirm_error_view) or
url_for('send_confirmation'))

Expand Down
11 changes: 11 additions & 0 deletions tests/test_confirmable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from utils import authenticate, logout

from flask_security.core import UserMixin
from flask_security.confirmable import generate_confirmation_token
from flask_security.signals import confirm_instructions_sent, user_confirmed
from flask_security.utils import capture_registrations, string_types

Expand Down Expand Up @@ -82,6 +83,16 @@ def on_instructions_sent(app, user, token):
# Test already confirmed
response = client.get('/confirm/' + token, follow_redirects=True)
assert get_message('ALREADY_CONFIRMED') in response.data
assert len(recorded_instructions_sent) == 2

# Test already confirmed and expired token
app.config['SECURITY_CONFIRM_EMAIL_WITHIN'] = '-1 days'
with app.app_context():
user = registrations[0]['user']
expired_token = generate_confirmation_token(user)
response = client.get('/confirm/' + expired_token, follow_redirects=True)
assert get_message('ALREADY_CONFIRMED') in response.data
assert len(recorded_instructions_sent) == 2

# Test already confirmed when asking for confirmation instructions
logout(client)
Expand Down

0 comments on commit b4e6c55

Please sign in to comment.