Prefer form error messages in some instances

This commit is contained in:
Matt Wright
2012-08-21 00:59:46 -04:00
parent 705b73afc1
commit f2d5028d7c
3 changed files with 8 additions and 17 deletions
-1
View File
@@ -43,7 +43,6 @@ _default_config = {
'CONFIRM_URL': '/confirm',
'POST_LOGIN_VIEW': '/',
'POST_LOGOUT_VIEW': '/',
'POST_FORGOT_VIEW': None,
'CONFIRM_ERROR_VIEW': None,
'POST_REGISTER_VIEW': None,
'POST_CONFIRM_VIEW': None,
+1 -1
View File
@@ -20,8 +20,8 @@ from .exceptions import UserNotFoundError
# Convenient reference
_datastore = LocalProxy(lambda: app.extensions['security'].datastore)
email_required = Required(message='Email not provided')
email_validator = Email(message='Invalid email address')
+7 -15
View File
@@ -91,6 +91,7 @@ def login():
confirm_url = url_for('send_confirmation', email=e.user.email)
except BadCredentialsError, e:
msg = str(e)
form.password.errors.append(msg)
if user:
if login_user(user, remember=form.remember.data):
@@ -98,16 +99,15 @@ def login():
if request.json:
return _json_auth_ok(user)
return redirect(get_post_login_redirect())
msg = get_message('DISABLED_ACCOUNT')[0]
form.email.errors.append(get_message('DISABLED_ACCOUNT')[0])
_logger.debug('Unsuccessful authentication attempt: %s' % msg)
if request.json:
return _json_auth_error(msg)
do_flash(msg, 'error')
if confirm_url:
do_flash(msg, 'error')
return redirect(confirm_url)
return render_template('security/login.html',
@@ -171,11 +171,9 @@ def send_login():
if user.is_active():
send_login_instructions(user, form.next.data)
msg = get_message('LOGIN_EMAIL_SENT', email=user.email)
do_flash(*get_message('LOGIN_EMAIL_SENT', email=user.email))
else:
msg = get_message('DISABLED_ACCOUNT')
do_flash(*msg)
form.email.errors.append(get_message('DISABLED_ACCOUNT')[0])
return render_template('security/send_login.html',
login_form=form,
@@ -249,12 +247,6 @@ def forgot_password():
_logger.debug('%s requested to reset their password' % user)
do_flash(*get_message('PASSWORD_RESET_REQUEST', email=user.email))
if _security.post_forgot_view:
return redirect(get_url(_security.post_forgot_view))
else:
for key, value in form.errors.items():
do_flash(value[0], 'error')
return render_template('security/forgot_password.html',
forgot_password_form=form,
**_ctx('forgot_password'))
@@ -264,7 +256,7 @@ def forgot_password():
def reset_password(token):
"""View function that handles a reset password request."""
next, msg = None, None
next = None
form = ResetPasswordForm(csrf_enabled=not app.testing)
if form.validate_on_submit():
@@ -282,7 +274,7 @@ def reset_password(token):
email=e.user.email)
_logger.debug('Password reset error: ' + msg[0])
do_flash(*msg)
do_flash(*msg)
if next:
login_user(user)