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 generate_users(): users = list() for item in fake_users: user = User.objects(username=item['username']).first() if user: users.append(user) continue user = User() role = Role.objects(name=item['role']).first() user.roles.append(role) user.username = item['username'] user.password = bcrypt.generate_password_hash("password") users.append(user) try: user.save() except Exception as e: log.error("Eror inserting user: %s, %s" % (str(user), e)) return users
def generate_users(): users = list() for item in fake_users: user = User.query.filter_by(username=item['username']).first() if user: users.append(user) continue user = User() poster = Role.query.filter_by(name=item['role']).one() user.roles.append(poster) user.username = item['username'] user.password = bcrypt.generate_password_hash("password") users.append(user) try: db.session.add(user) db.session.commit() except Exception as e: log.error("Eror inserting user: %s, %s" % (str(user), e)) db.session.rollback() return users