mirror of
https://github.com/wassname/flask-security.git
synced 2026-09-09 11:22:35 +08:00
Improve RegisterUserForm
This commit is contained in:
+16
-1
@@ -21,6 +21,14 @@ from .exceptions import UserNotFoundError
|
||||
_datastore = LocalProxy(lambda: app.extensions['security'].datastore)
|
||||
|
||||
|
||||
def unique_user_email(form, field):
|
||||
try:
|
||||
_datastore.find_user(email=field.data)
|
||||
raise ValidationError('%s is already associated with an account' % field.data)
|
||||
except UserNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def valid_user_email(form, field):
|
||||
try:
|
||||
_datastore.find_user(email=field.data)
|
||||
@@ -41,6 +49,13 @@ class UserEmailFormMixin():
|
||||
valid_user_email])
|
||||
|
||||
|
||||
class UniqueEmailFormMixin():
|
||||
email = TextField("Email Address",
|
||||
validators=[Required(message="Email not provided"),
|
||||
Email(message="Invalid email address"),
|
||||
unique_user_email])
|
||||
|
||||
|
||||
class PasswordFormMixin():
|
||||
password = PasswordField("Password",
|
||||
validators=[Required(message="Password not provided")])
|
||||
@@ -102,7 +117,7 @@ class LoginForm(Form, EmailFormMixin, PasswordFormMixin):
|
||||
|
||||
|
||||
class RegisterForm(Form,
|
||||
EmailFormMixin,
|
||||
UniqueEmailFormMixin,
|
||||
PasswordFormMixin,
|
||||
PasswordConfirmFormMixin):
|
||||
"""The default register form"""
|
||||
|
||||
Reference in New Issue
Block a user