def update_user_me(
        *,
        password: str = Body(None),
        email: EmailStr = Body(None),
        current_user: DBUser = Depends(get_current_active_user),
):
    """
    Update own user.
    """
    current_user_data = current_user.to_mongo()
    user_in = UserUpdate(**current_user_data)
    if password is not None:
        user_in.password = password
    if email is not None:
        user_in.email = email
    user = crud.user.update(db_obj=current_user, obj_in=user_in)
    return user
示例#2
0
def update_user_me(
        *,
        db: Session = Depends(get_db),
        password: str = Body(None),
        name: str = Body(None),
        email: EmailStr = Body(None),
        current_user: DBUser = Depends(get_current_active_user),
):
    """
    Update own user.
    """
    current_user_data = jsonable_encoder(current_user)
    user_in = UserUpdate(**current_user_data)
    if password is not None:
        user_in.password = password
    if name is not None:
        user_in.full_name = name
    if email is not None:
        user_in.email = email
    user = crud.user.update(db, db_obj=current_user, obj_in=user_in)
    return user
示例#3
0
def update_user_me(
        *,
        db: Session = Depends(get_db),
        user_in: OpenUserUpdate,
        current_user: DBUser = Depends(get_current_active_user),
):
    """
    Update own user.
    """

    current_user_data = jsonable_encoder(current_user)
    update_user_in = UserUpdate(**current_user_data)
    if user_in.password is not None:
        update_user_in.password = user_in.password
    if user_in.email is not None:
        update_user_in.email = user_in.email
    if user_in.full_name is not None:
        update_user_in.full_name = user_in.full_name

    user = crud.user.update(db, user=current_user, user_in=update_user_in)
    return user