Example #1
0
def test_get_user_different_usernames():
    email = random_lower_string()
    password = random_lower_string()
    username = random_lower_string()
    user = create_or_get_user(email, password)
    user_2 = get_user(username)
    assert user != user_2
Example #2
0
def route_users_id_get(username):
    current_user = get_current_user()  # type: User
    if not current_user:
        abort(400, "Could not authenticate user with provided token")
    elif not check_if_user_is_active(current_user):
        abort(400, "Inactive user")
    user = get_user(username)
    if user == current_user:
        return user
    if not check_if_user_is_superuser(current_user):
        abort(400, "Not a superuser")
    return user
Example #3
0
def route_users_post_open(username=None, password=None):
    if not config.USERS_OPEN_REGISTRATION:
        abort(403, "Open user resgistration is forbidden on this server")
    client = get_client()
    db_users = get_db_users(client)

    user = get_user(username, db_users, client)

    if user:
        return abort(
            400, f"The user with this username already exists in the system")

    user = create_user_with_default_db(username, password, db_users, client)
    return user
Example #4
0
def route_users_username_dbid_get(username):
    current_user = get_current_user()  # type: User
    if not current_user:
        abort(400, "Could not authenticate user with provided token")
    elif not check_if_user_is_active(current_user):
        abort(400, "Inactive user")
    user = get_user(username)
    user_db_id = get_database_id_for_user(username)
    response = {"msg": user_db_id}
    if user == current_user:
        return response
    if not check_if_user_is_superuser(current_user):
        abort(400, "Not a superuser")
    return response
Example #5
0
def route_users_post(username=None, password=None):
    current_user = get_current_user()

    if not current_user:
        abort(400, "Could not authenticate user with provided token")
    elif not check_if_user_is_active(current_user):
        abort(400, "Inactive user")
    elif not check_if_user_is_superuser(current_user):
        abort(400, "Not a superuser")
    user = get_user(username)
    if user:
        return abort(
            400, f"The user with this username already exists in the system.")
    user = create_user_with_default_db(username, password)
    return user
Example #6
0
def get_current_user(identity):
    return get_user(identity)
def get_current_user(identity):
    return get_user(identity, db_session)
Example #8
0
def test_get_user():
    password = random_lower_string()
    username = random_lower_string()
    user = create_or_get_user(username, password)
    user_2 = get_user(username)
    assert user == user_2