From c49d9b57eddc83f1aab1b85bd3971b5f29d1dcf7 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Fri, 1 Feb 2013 17:32:54 -0500 Subject: [PATCH] Make login form messages configurable --- flask_security/core.py | 6 +++++- flask_security/forms.py | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flask_security/core.py b/flask_security/core.py index b30af10..7a62699 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -91,10 +91,14 @@ _default_messages = { 'LOGIN_EMAIL_SENT': ('Instructions to login have been sent to %(email)s.', 'success'), 'INVALID_LOGIN_TOKEN': ('Invalid login token.', 'error'), 'DISABLED_ACCOUNT': ('Account is disabled.', 'error'), + 'EMAIL_NOT_PROVIDED': ('Email not provided', 'error'), + 'PASSWORD_NOT_PROVIDED': ('Password not provided', 'error'), + 'USER_DOES_NOT_EXIST': ('Specified user does not exist', 'error'), + 'INVALID_PASSWORD': ('Invalid password', 'error'), 'PASSWORDLESS_LOGIN_SUCCESSFUL': ('You have successfuly logged in.', 'success'), 'PASSWORD_RESET': ('You successfully reset your password and you have been logged in automatically.', 'success'), 'LOGIN': ('Please log in to access this page.', 'info'), - 'REFRESH': ('Please reauthenticate to access this page.', 'info') + 'REFRESH': ('Please reauthenticate to access this page.', 'info'), } _allowed_password_hash_schemes = [ diff --git a/flask_security/forms.py b/flask_security/forms.py index 27dd675..ccdfc08 100644 --- a/flask_security/forms.py +++ b/flask_security/forms.py @@ -159,20 +159,20 @@ class LoginForm(Form, NextFormMixin): return False if self.email.data.strip() == '': - self.email.errors.append('Email not provided') + self.email.errors.append(get_message('EMAIL_NOT_PROVIDED')[0]) return False if self.password.data.strip() == '': - self.password.errors.append('Password not provided') + self.password.errors.append(get_message('PASSWORD_NOT_PROVIDED')[0]) return False self.user = _datastore.find_user(email=self.email.data) if self.user is None: - self.email.errors.append('Specified user does not exist') + self.email.errors.append(get_message('USER_DOES_NOT_EXIST')[0]) return False if not verify_and_update_password(self.password.data, self.user): - self.password.errors.append('Invalid password') + self.password.errors.append(get_message('INVALID_PASSWORD')[0]) return False if requires_confirmation(self.user): self.email.errors.append(get_message('CONFIRMATION_REQUIRED')[0])