def add_users(db: directives.PeeweeSession, filename: hug.types.text,
              role: hug.types.one_of(UserRoles.user_roles()) = UserRoles.USER):
    """
    [--filename] <string> [--role <one_of(UserRoles.user_roles()) = UserRoles.USER>]; imports usernames from the file, one user per line, with a default of 10 coupons
    """
    with open(filename) as f:
        return [_add_one_user(db, line.strip(), role=role) for line in f]
def add_user(db: directives.PeeweeSession, username: hug.types.text, password: hug.types.text = None,
             role: hug.types.one_of(UserRoles.user_roles()) = UserRoles.USER,
             coupons: hug.types.number = 10):
    """
    [--username] <string> [--password] <string> [--role <one_of(UserRoles.user_roles()) = UserRoles.USER>] [--coupons <number=10>]; creates a user
    """
    return [_add_one_user(db, username, password, role, coupons)]
def _add_one_user(db: directives.PeeweeSession, username: hug.types.text, password: hug.types.text = None,
                  role: hug.types.one_of(UserRoles.user_roles()) = UserRoles.USER,
                  coupons: hug.types.number = 10):
    with db.atomic():
        name = username.lower()
        salt = get_random_string(2)
        secret_password = password or get_random_string(12)
        hashed_password = hash_pw(name, salt, secret_password)
        user = User.create(user_name=name, role=role, salt=salt,
                           password=hashed_password, coupons=coupons)
        user.save()
        return {"name": user.user_name, "password": secret_password}
예제 #4
0
def add_users(db: directives.PeeweeSession,
              filename: hug.types.text,
              role: hug.types.one_of(UserRoles.user_roles()) = UserRoles.USER):
    with open(filename) as f:
        return [_add_one_user(db, line.strip(), role=role) for line in f]
예제 #5
0
def add_user(db: directives.PeeweeSession,
             username: hug.types.text,
             password: hug.types.text = None,
             role: hug.types.one_of(UserRoles.user_roles()) = UserRoles.USER,
             coupons: hug.types.number = 10):
    return [_add_one_user(db, username, password, role, coupons)]
def get_user_roles():
    """
    get a list of available user_roles
    """
    return UserRoles.user_roles()