检索POST数据在Api平台中不起作用

时间:2019-07-03 18:47:57

标签: php json symfony4 api-platform.com

我有以下curl命令。

POST {{url}}/api/users/:id/reset-password?reset_key=b77b780972757de038b51fe00072069e2ad76706

{
    "password": "password2"
}

我正在使用$request->request->get('password'); 但它返回null;

  

“ hydra:title”:“发生错误”,      “ hydra:description”:“无法自动验证\” NULL \“>类型的值。请提供约束。”,

这是我的UserController

public function resetPassword($data, Request $request, UserService $userService)
    {
        /** @var User $userFromRequest */
        $userFromRequest = $data;

        $resetKey = $request->query->get('reset_key');
        if ($resetKey === null) {
            throw new AccessDeniedException();
        }

        $userFromDatabase = $userService->getUserById($userFromRequest->getId());
        if ($userFromDatabase === null) {
            throw new AccessDeniedException();
        }

        if ($userFromRequest->getId() !== $userFromDatabase->getId()) {
            throw new AccessDeniedException();
        }

        if ($resetKey !== $userFromDatabase->getResetKey()) {
            throw new AccessDeniedException();
        }

        $now = new \DateTime();
        $isGreaterThan24Hours = $userFromDatabase->getResetRequestAt()
                ->diff($now)->format('H') > 24;

        //return $isGreaterThan24Hours;

        if ($isGreaterThan24Hours) {
            throw new AccessDeniedException();
        }

        return $request->request->get('password');
        // set user pssword

        $userService->resetPassword($userFromDatabase);

        return $userFromDatabase;
    }

0 个答案:

没有答案