def _insert_user(self, username, password, role_name): test_role = Role(role_name) db.session.add(test_role) db.session.commit() test_user = User(username) test_user.set_password(password) db.session.add(test_user) db.session.commit()
def process_reg(): form = RegistrationForm() if form.validate_on_submit(): new_user = User(login=form.username.data) new_user.set_password(form.password.data) db.session.add(new_user) db.session.commit() flash('Вы успешно зарегистрировались!') return redirect(url_for('auth.login')) flash('Исправьте пожалуйста ошибки в форме.') return redirect(url_for('auth.register'))
def _insert_user(self, username, password, rolename): role = Role.query.filter_by(description=rolename).first() user = User.query.filter_by(username=username) if user is None: user = User() user.username = username user.set_password(password) if role: user.roles.append(role) db.session.add(user) db.session.commit()
def _insert_user(self, email, f_name, password, role): """ Create role and user :param email: User's email :param f_name: User's first name :param password: User's account password :param role: User's blog role """ with self.app.app_context(): test_role = Role(role) db.session.add(test_role) db.session.commit() test_user = User(email=email, f_name=f_name) test_user.set_password(password) db.session.add(test_user) db.session.commit()
def generate_users(): users = list() for item in fake_users: user = User(username=item['username']) if user: users.append(user) # continue user = User() role = Role.objects(name=item['role']).first() user.roles.append(role) user.username = item['username'] user.set_password("password") users.append(user) try: user.save() except Exception as e: log.error("Error inserting user: %s, %s" % (str(user), e)) return users
from webapp import create_app, db from webapp.auth.models import User, Role app = create_app('config.TestConfig') db.app = app db.create_all() with app.app_context(): user_role = Role("user") author_role = Role("author") db.session.add(user_role) db.session.add(author_role) db.session.commit() test_user = User(email="*****@*****.**", f_name="test") test_user.set_password("test") test_user.roles.append(author_role) db.session.add(test_user) db.session.commit() app.run()