mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-01 16:50:07 +08:00
RegisterFormMixin can now to_dict all fields.
It adds a to_dict function that uses inspect to add all wtf Field to the returned dict. This allows extensions to the register form to easily add fields that will be passed to the datastore's create_user function.
This commit is contained in:
@@ -9,10 +9,12 @@
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
|
||||
from flask import request, current_app
|
||||
from flask.ext.wtf import Form as BaseForm, TextField, PasswordField, \
|
||||
SubmitField, HiddenField, Required, BooleanField, EqualTo, Email, \
|
||||
ValidationError, Length
|
||||
ValidationError, Length, Field
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .confirmable import requires_confirmation
|
||||
@@ -89,6 +91,10 @@ class NextFormMixin():
|
||||
class RegisterFormMixin():
|
||||
submit = SubmitField("Register")
|
||||
|
||||
def to_dict(form):
|
||||
fields = inspect.getmembers(form, lambda member: isinstance(member, Field))
|
||||
return dict((key, value.data) for key, value in fields)
|
||||
|
||||
|
||||
class SendConfirmationForm(Form, UserEmailFormMixin):
|
||||
"""The default forgot password form"""
|
||||
@@ -172,10 +178,7 @@ class LoginForm(Form, NextFormMixin):
|
||||
|
||||
class ConfirmRegisterForm(Form, RegisterFormMixin,
|
||||
UniqueEmailFormMixin, NewPasswordFormMixin):
|
||||
def to_dict(self):
|
||||
return dict(email=self.email.data,
|
||||
password=self.password.data)
|
||||
|
||||
pass
|
||||
|
||||
class RegisterForm(ConfirmRegisterForm, PasswordConfirmFormMixin):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user