Esempio n. 1
0
    def mutate(root, info, user_id, password, new_password):

        update_user = schemas.UserPasswordChange(password=password,
                                                 new_password=new_password)
        message = "success"
        is_password_correct = crud_users.check_password(
            user_id=user_id, password=update_user.password, db=db)
        if is_password_correct is False:
            raise GraphQLError("Invalid Old password")

        db_update = crud_users.change_user_password(
            user_id=user_id, password=update_user.new_password, db=db)
        if db_update is None:
            raise GraphQLError("Internal Server Error")
        return CreateUser(message=message)
Esempio n. 2
0
def update_password(
    user_id: str,
    user: schemas.UserPasswordChange,
    current_user: schemas.UserVerify = Depends(deps.get_current_user)
) -> JSONResponse:
    """ Update User Password"""
    is_password_correct = crud_users.check_password(user_id=user_id,
                                                    password=user.password)
    if is_password_correct is False:
        return JSONResponse(status_code=400,
                            content={"message": "Invalid password"})

    data = crud_users.change_user_password(user_id=user_id,
                                           password=user.new_password)
    if data is None:
        return JSONResponse(status_code=500,
                            content={"message": "Internal Server Error"})

    return JSONResponse(status_code=200, content={"message": "success"})