def user(username, email, password, role, active): """Create a new application user.""" from tracker import db from tracker.user import hash_password from tracker.user import random_string user_by_name = db.get(User, name=username) if user_by_name: echo('Error: username already exists', err=True) exit(1) user_by_email = db.get(User, email=email) if user_by_email: echo('Error: e-mail already exists', err=True) exit(1) user = User() user.name = username user.email = email user.salt = random_string() user.password = hash_password(password, user.salt) user.role = UserRole.fromstring(role) user.active = active db.session.add(user) db.session.commit()
def wrapper(db, *args, **kwargs): user = User() user.active = active user.name = username user.password = password if password else username user.role = role user.email = email if email else '{}@cyber.cyber'.format(username) user.salt = salt if salt else random_string() user.password = hash_password(user.password, user.salt) user.idp_id = idp_id db.session.add(user) db.session.commit() func(db=db, *args, **kwargs)