def register(params, login=True, commit=True): """ Create / register a user. """ if UserQueries.get_by_login(params.get("username", "")): raise UserServicesException( 'User with given username exists already.') user = User() model_fields = get_fields(User) # apply all fields to object. set_fields_from_dict(user, params, model_fields) user.login = params.get("username") user.password = generate_password_hash(params.get("password")) if commit: db.session.add(user) db.session.commit() if login: login_user(user) return user
def register(params, login=True, commit=True): """ Create / register a user. """ if UserQueries.get_by_login(params.get("username", "")): raise UserServicesException('User with given username exists already.') user = User() model_fields = get_fields(User) # apply all fields to object. set_fields_from_dict(user, params, model_fields) user.login=params.get("username") user.password=generate_password_hash(params.get("password")) if commit: db.session.add(user) db.session.commit() if login: login_user(user) return user
def create_tables(): print('Creating tables...') db.create_all() if db.session.query(User).count() == 0: # create super user. test_user = User() test_user.login="******" test_user.first_name = "Joe" test_user.last_name = "Lucas" test_user.password=generate_password_hash("test") test_user.is_super = True db.session.add(test_user) db.session.commit() test_user = User() test_user.login="******" test_user.first_name = "Bob" test_user.last_name = "Average" test_user.password=generate_password_hash("test") test_user.is_super = False db.session.add(test_user) db.session.commit()
def register_view(self): form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): user = User() form.populate_obj(user) # we hash the users password to avoid saving it as plaintext in the db, # remove to use plain text: user.password = generate_password_hash(form.password.data) db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.index')) link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(FAdminIndexView, self).index()
def register_view(self): form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): user = User() form.populate_obj(user) # we hash the users password to avoid saving it as plaintext in the db, # remove to use plain text: user.password = generate_password_hash(form.password.data) db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.index')) link = '<p>Already have an account? <a href="' + url_for( '.login_view') + '">Click here to log in.</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(FAdminIndexView, self).index()