mirror of
https://github.com/wassname/flask-security.git
synced 2026-08-01 12:30:14 +08:00
Make password length message configurable.
This commit is contained in:
@@ -110,6 +110,7 @@ _default_messages = {
|
||||
'EMAIL_NOT_PROVIDED': ('Email not provided', 'error'),
|
||||
'INVALID_EMAIL_ADDRESS': ('Invalid email address', 'error'),
|
||||
'PASSWORD_NOT_PROVIDED': ('Password not provided', 'error'),
|
||||
'PASSWORD_INVALID_LENGTH': ('Password must be at least 6 characters', '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'),
|
||||
|
||||
@@ -69,6 +69,7 @@ class Length(ValidatorMixin, wtf.Length):
|
||||
email_required = Required(message='EMAIL_NOT_PROVIDED')
|
||||
email_validator = Email(message='INVALID_EMAIL_ADDRESS')
|
||||
password_required = Required(message='PASSWORD_NOT_PROVIDED')
|
||||
password_length = Length(min=6, max=128, message='PASSWORD_INVALID_LENGTH')
|
||||
|
||||
|
||||
def get_form_field_label(key):
|
||||
@@ -122,8 +123,7 @@ class PasswordFormMixin():
|
||||
|
||||
class NewPasswordFormMixin():
|
||||
password = PasswordField(get_form_field_label('password'),
|
||||
validators=[password_required,
|
||||
Length(min=6, max=128)])
|
||||
validators=[password_required, password_length])
|
||||
|
||||
|
||||
class PasswordConfirmFormMixin():
|
||||
@@ -256,8 +256,7 @@ class ChangePasswordForm(Form, PasswordFormMixin):
|
||||
"""The default change password form"""
|
||||
|
||||
new_password = PasswordField(get_form_field_label('new_password'),
|
||||
validators=[password_required,
|
||||
Length(min=6, max=128)])
|
||||
validators=[password_required, password_length])
|
||||
|
||||
new_password_confirm = PasswordField(get_form_field_label('retype_password'),
|
||||
validators=[EqualTo('new_password', message='RETYPE_PASSWORD_MISMATCH')])
|
||||
|
||||
@@ -459,7 +459,7 @@ class ChangePasswordTest(SecurityTest):
|
||||
'new_password_confirm': 'a'
|
||||
}, follow_redirects=True)
|
||||
self.assertNotIn('You successfully changed your password', r.data)
|
||||
self.assertIn('Field must be between', r.data)
|
||||
self.assertIn('Password must be at least 6 characters', r.data)
|
||||
|
||||
def test_change_password_success(self):
|
||||
self.authenticate()
|
||||
|
||||
Reference in New Issue
Block a user