def create_users_list(users_number): user_name_set = set() while len(user_name_set) < users_number: user_name_set.add(return_random_string(1, 50)) user_name_list = list(user_name_set) user_list = [User( username='******', email='*****@*****.**', password='******', active=True)] iteration = 0 while iteration < users_number: username = user_name_list[iteration] email = username + '@supermail.mail' user_list.append( User( username=username, email=email, password=return_random_string(10, 107), active=True ) ) iteration += 1 db.session.add_all(user_list) db.session.flush() return user_list
def add_user(username, email, password, role): "Creates an admin, an editor a basic level (if role is None) user" message = '' user = User(username=username, email=email, password=hash_password(password), active=True) if role: if role.lower() == EDITOR_ROLE.lower(): user.roles.append(Role.query.filter_by(name=EDITOR_ROLE).one()) message = 'Editor created' elif role.lower() == ADMIN_ROLE.lower(): user.roles.append(Role.query.filter_by(name=ADMIN_ROLE).one()) message = 'Admin created' else: message = 'User created' db.session.add(user) db.session.commit() return message
def create_user(self, email): return User.register_or_login(email)
def test_login(): email = request.form.get("email") user = User.register_or_login(email) login_user(user) return "ok"