Esempio n. 1
0
    def register_user(self):
        """Prompt for user details."""
        # Get the information.
        email = prompt('Email')
        name = prompt('Name')
        password = prompt_pass('Password')
        password_confirm = prompt_pass('Confirm Password')

        data = MultiDict({
            'email': email,
            'password': password,
            'password_confirm': password_confirm,
        })

        # Validate the form.
        form = RegisterForm(data, csrf_enabled=False)
        if form.validate():
            # Register the new user.
            user = register_user(name=name, email=email, password=password)

            print('\nUser created successfully.')
            print('User(id={} email={})'.format(user.id, user.email))

            return user

        # If something went wrong, report it and exit out.
        print('\nError creating user:'******'\n'.join(errors))
        sys.exit(1)
Esempio n. 2
0
def users():
    user = current_user._get_current_object()
    registered = 'false'
    register_form = RegisterForm()
    if request.method == 'GET':
        users = User.query.all()
        return render_template('users.html',
                               user=user,
                               users=users,
                               register_user_form=register_form,
                               registered=registered)
    else:
        if register_form.validate_on_submit() or register_form.validate():
            user = User()
            register_form.populate_obj(user)
            user_datastore.create_user(email=user.email,
                                       password=hash_password(user.password))
            db_session.commit()
            registered = 'true'
        else:
            visible = 'block'
        users = User.query.all()
        return render_template('users.html',
                               user=user,
                               users=users,
                               register_user_form=register_form,
                               registered=registered)
Esempio n. 3
0
 def run(self):
     email = prompt('Email')
     password = prompt_pass('Password')
     password_confirm = prompt_pass('Confirm Password')
     fullname = prompt('Fullname')
     tel = prompt('Tel')
     active = bool(prompt('Actvice immediately', default='True'))
     role = prompt('Role', default='admin')
     data = MultiDict(
         dict(email=email,
              password=password,
              password_confirm=password_confirm,
              fullname=fullname,
              tel=tel,
              active=active,
              role=role))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email,
                              password=password,
                              fullname=fullname,
                              tel=tel,
                              active=active,
                              role=role)
         print("\nUser created successfully")
         print("User(id=%s,email=%s,fullname=%s)" %
               (user.id, user.email, user.fullname))
         return
     print("\nError creating user:"******"\n".join(errors))
Esempio n. 4
0
    def run(self):
        email = prompt('Email')
        password = prompt_pass('Password')
        password_confirm = prompt_pass('Confirm Password')

        ListRolesCommand().run()
        role_names = prompt("This user's comma-separated roles")
        role_models = []
        for name in role_names.split(','):
            r = roles.first(name=name.strip())
            if not r:
                print('Invalid role: %s' % name.strip())
            else:
                role_models.append(r)

        data = MultiDict(dict(email=email, password=password, password_confirm=password_confirm))
        form = RegisterForm(data, csrf_enabled=False)
        if form.validate():
            user = register_user(email=email, password=password)
            user.roles = role_models
            db.session.add(user)
            db.session.commit()
            print('\nUser created successfully')
            print('User(id=%s email=%s, roles=%s)' % (user.id, user.email,
                ','.join([r.name for r in user.roles])))
        else:
            print('\nError creating user:'******'\n'.join(errors))
Esempio n. 5
0
 def run(self):
     email = prompt('Email')
     password = prompt_pass('Password')
     password_confirm = prompt_pass('Confirm Password')
     data = MultiDict(dict(email=email, password=password, password_confirm=password_confirm))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email, password=password)
         print('\nUser created successfully')
         print('User(id=%s email=%s)' % (user.id, user.email))
         return
     print('\nError creating user:'******'\n'.join(errors))
Esempio n. 6
0
 def run(self):
     email = prompt('Email')
     password = prompt_pass('Password')
     password_confirm = prompt_pass('Confirm Password')
     data = MultiDict(dict(email=email, password=password, password_confirm=password_confirm))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email, password=password)
         print '\nUser created successfully'
         print 'User(id=%s email=%s)' % (user.id, user.email)
         return
     print '\nError creating user:'******'\n'.join(errors)
Esempio n. 7
0
 def run(self):
     email = prompt("Email")
     password = prompt_pass("Password")
     password_confirm = prompt_pass("Confirm password")
     data = MultiDict(dict(email=email, password=password,
                           password_confirm=password_confirm))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email, password=password)
         print "\nUser created."
         print "<User id=%s email=%s>" % (user.id, user.email)
     else:
         print "Error:"
         for errors in form.errors.values():
             print "\n".join(errors)
Esempio n. 8
0
 def run(self):
     email = prompt("Email")
     password = prompt_pass("Password")
     password_confirm = prompt_pass("Confirm password")
     data = MultiDict(
         dict(email=email,
              password=password,
              password_confirm=password_confirm))
     form = RegisterForm(data, csrf_enabled=False)
     if form.validate():
         user = register_user(email=email, password=password)
         print "\nUser created."
         print "<User id=%s email=%s>" % (user.id, user.email)
     else:
         print "Error:"
         for errors in form.errors.values():
             print "\n".join(errors)
Esempio n. 9
0
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)
Esempio n. 10
0
def create():
    '''Create a new user'''
    data = {
        'first_name': prompt('First name'),
        'last_name': prompt('Last name'),
        'email': prompt('Email'),
        'password': prompt_pass('Password'),
        'password_confirm': prompt_pass('Confirm Password'),
    }
    form = RegisterForm(MultiDict(data), csrf_enabled=False)
    if form.validate():
        data['password'] = encrypt_password(data['password'])
        del data['password_confirm']
        data['confirmed_at'] = datetime.utcnow()
        user = datastore.create_user(**data)
        print '\nUser created successfully'
        print 'User(id=%s email=%s)' % (user.id, user.email)
        return user
    print '\nError creating user:'******'\n'.join(errors)
Esempio n. 11
0
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)