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:    License: GNU Affero General Public License v3.0 6 votes vote down vote up
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 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={} 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:    License: MIT License 5 votes vote down vote up
def test_form_data_is_passed_to_user_registered_signal(app, sqlalchemy_datastore):
    class MyRegisterForm(RegisterForm):
        additional_field = StringField("additional_field") = Security(
        app, datastore=sqlalchemy_datastore, register_form=MyRegisterForm

    recorded = []

    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"


    client = app.test_client()

    data = dict(
    response ="/register", data=data, follow_redirects=True)

    assert response.status_code == 200
    assert len(recorded) == 1