예제 #1
0
def get_current_user_profile(
        current_user: User = Depends(get_current_active_user)):
    """
    Export the data of the current user to the client.

    :param current_user: Currently logged in user to have data exported. This field is auto filled by the HTTP request
    :return: User profile details, excluding hashed password.
    """
    user_export_data = current_user.dict(exclude={'password', 'id'})
    return user_export_data
def add_user_db(user: User) -> bool:
    """
    Adds a new user to the database.

    :param user: User object to add to database
    :return: True if added, else False if error.
    """

    # If request didn't specify permissions, ensure that none are stored in the database.
    if user.roles is None:
        roles = []

    if not user_collection.find_one({"username": user.username}):
        user_collection.insert_one(user.dict())
        return True

    return False  # This means there is already a user in the database with this name.