From f2d5028d7c8f220d7b63725ef91325492cf36760 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 21 Aug 2012 00:59:46 -0400 Subject: [PATCH] Prefer form error messages in some instances --- flask_security/core.py | 1 - flask_security/forms.py | 2 +- flask_security/views.py | 22 +++++++--------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/flask_security/core.py b/flask_security/core.py index b731feb..dbb6f3e 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -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, diff --git a/flask_security/forms.py b/flask_security/forms.py index c5b9443..1c46c48 100644 --- a/flask_security/forms.py +++ b/flask_security/forms.py @@ -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') diff --git a/flask_security/views.py b/flask_security/views.py index 6a359c7..20f429c 100644 --- a/flask_security/views.py +++ b/flask_security/views.py @@ -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)