Python flask_security.forms.RegisterForm() Examples
The following are 2
code examples of flask_security.forms.RegisterForm().
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_security.forms
, or try the search function
.

Example #1
Source Project: udata Author: opendatateam File: commands.py License: GNU Affero General Public License v3.0 | 6 votes |
def create(): '''Create a new user''' data = { 'first_name': click.prompt('First name'), 'last_name': click.prompt('Last name'), 'email': click.prompt('Email'), 'password': click.prompt('Password', hide_input=True), 'password_confirm': click.prompt('Confirm Password', hide_input=True), } # Until https://github.com/mattupstate/flask-security/issues/672 is fixed with current_app.test_request_context(): form = RegisterForm(MultiDict(data), meta={'csrf': False}) if form.validate(): data['password'] = encrypt_password(data['password']) del data['password_confirm'] data['confirmed_at'] = datetime.utcnow() user = datastore.create_user(**data) success('User(id={u.id} email={u.email}) created'.format(u=user)) return user errors = '\n'.join('\n'.join(e) for e in form.errors.values()) exit_with_error('Error creating user', errors)
Example #2
Source Project: flask-security Author: Flask-Middleware File: test_registerable.py License: MIT License | 5 votes |
def test_form_data_is_passed_to_user_registered_signal(app, sqlalchemy_datastore): class MyRegisterForm(RegisterForm): additional_field = StringField("additional_field") app.security = Security( app, datastore=sqlalchemy_datastore, register_form=MyRegisterForm ) recorded = [] @user_registered.connect_via(app) def on_user_registered(app, user, confirm_token, form_data): assert isinstance(app, Flask) assert isinstance(user, UserMixin) assert confirm_token is None assert form_data["additional_field"] == "additional_data" recorded.append(user) client = app.test_client() data = dict( email="dude@lp.com", password="password", password_confirm="password", additional_field="additional_data", ) response = client.post("/register", data=data, follow_redirects=True) assert response.status_code == 200 assert len(recorded) == 1