This commit is contained in:
Matt Wright
2012-08-14 16:59:05 -04:00
parent 0524271573
commit ce6c5dcf31
4 changed files with 20 additions and 17 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ def send_confirmation_instructions(user, token):
:param user: The user to send the instructions to
"""
url = url_for('flask_security.confirm_account', token=token)
url = url_for('flask_security.confirm_email', token=token)
confirmation_link = request.url_root[:-1] + url
+5 -5
View File
@@ -69,14 +69,14 @@ _default_config = {
#: Default Flask-Security flash messages
_default_flash_messages = {
'UNAUTHORIZED': ('You do not have permission to view this resource.', 'error'),
'ACCOUNT_CONFIRMED': ('Your account has been confirmed. You may now log in.', 'success'),
'ALREADY_CONFIRMED': ('Your account has already been confirmed', 'info'),
'EMAIL_CONFIRMED': ('Your email has been confirmed. You may now log in.', 'success'),
'ALREADY_CONFIRMED': ('Your email has already been confirmed', 'info'),
'INVALID_CONFIRMATION_TOKEN': ('Invalid confirmation token', 'error'),
'PASSWORD_RESET_REQUEST': ('Instructions to reset your password have been sent to %(email)s.', 'info'),
'PASSWORD_RESET_EXPIRED': ('You did not reset your password within %(within)s. New instructions have been sent to %(email)s.', 'error'),
'INVALID_RESET_PASSWORD_TOKEN': ('Invalid reset password token', 'error'),
'CONFIRMATION_REQUEST': ('A new confirmation code has been sent to %(email)s.', 'info'),
'CONFIRMATION_EXPIRED': ('You did not confirm your account within %(within)s. New instructions to confirm your account have been sent to %(email)s.', 'error')
'CONFIRMATION_EXPIRED': ('You did not confirm your email within %(within)s. New instructions to confirm your email have been sent to %(email)s.', 'error')
}
@@ -310,10 +310,10 @@ class AuthenticationProvider(object):
try:
user = self._get_user(username_or_email)
except exceptions.UserNotFoundError:
raise exceptions.BadCredentialsError("Specified user does not exist")
raise exceptions.BadCredentialsError('Specified user does not exist')
if requires_confirmation(user):
raise exceptions.BadCredentialsError('Account requires confirmation')
raise exceptions.BadCredentialsError('Email requires confirmation')
# compare passwords
if verify_password(password, user.password,
+5 -5
View File
@@ -149,11 +149,11 @@ def send_confirmation():
reset_confirmation_form=form)
def confirm_account(token):
"""View function which handles a account confirmation request."""
def confirm_email(token):
"""View function which handles a email confirmation request."""
try:
user = confirm_by_token(token)
_logger.debug('%s confirmed their account' % user)
_logger.debug('%s confirmed their email' % user)
except ConfirmationError, e:
msg, cat = str(e), 'error'
@@ -171,7 +171,7 @@ def confirm_account(token):
return redirect(get_url(_security.confirm_error_view))
do_flash(get_message('ACCOUNT_CONFIRMED'))
do_flash(get_message('EMAIL_CONFIRMED'))
return redirect(_security.post_confirm_view or _security.post_login_view)
@@ -263,6 +263,6 @@ def create_blueprint(app, name, import_name, **kwargs):
endpoint='send_confirmation')(send_confirmation)
bp.route(config_value('CONFIRM_URL', app=app) + '/<token>',
methods=['GET', 'POST'],
endpoint='confirm_account')(confirm_account)
endpoint='confirm_email')(confirm_email)
return bp
+9 -6
View File
@@ -272,7 +272,7 @@ class ConfirmableTests(SecurityTest):
e = 'dude@lp.com'
self.register(e)
r = self.authenticate(email=e)
self.assertIn('Account requires confirmation', r.data)
self.assertIn('Email requires confirmation', r.data)
def test_register_sends_confirmation_email(self):
e = 'dude@lp.com'
@@ -289,7 +289,9 @@ class ConfirmableTests(SecurityTest):
token = registrations[0]['confirm_token']
r = self.client.get('/confirm/' + token, follow_redirects=True)
self.assertIn('Your account has been confirmed. You may now log in.', r.data)
msg = self.app.config['SECURITY_MSG_EMAIL_CONFIRMED'][0]
self.assertIn(msg, r.data)
def test_confirm_email_twice_flashes_already_confirmed_message(self):
e = 'dude@lp.com'
@@ -301,7 +303,9 @@ class ConfirmableTests(SecurityTest):
url = '/confirm/' + token
self.client.get(url, follow_redirects=True)
r = self.client.get(url, follow_redirects=True)
self.assertIn('Your account has already been confirmed', r.data)
msg = self.app.config['SECURITY_MSG_ALREADY_CONFIRMED'][0]
self.assertIn(msg, r.data)
def test_invalid_token_when_confirming_email(self):
r = self.client.get('/confirm/bogus', follow_redirects=True)
@@ -338,9 +342,8 @@ class ExpiredConfirmationTest(SecurityTest):
self.assertNotIn(token, outbox[0].html)
expire_text = self.AUTH_CONFIG['SECURITY_CONFIRM_EMAIL_WITHIN']
text = 'You did not confirm your account within %s' % expire_text
self.assertIn(text, r.data)
msg = self.app.config['SECURITY_MSG_CONFIRMATION_EXPIRED'][0] % dict(within=expire_text, email=e)
self.assertIn(msg, r.data)
class LoginWithoutImmediateConfirmTests(SecurityTest):