service = $service; $this->user = $user; if ( !$this->user->isAdmin() && !$this->user->isRegular() && !$this->user->isPortal() ) { throw new Forbidden(); } } /** * @throws BadRequest * @throws Forbidden * @throws NotFound */ public function getActionRead(Request $request): stdClass { $id = $request->getRouteParam('id'); if (!$id) { throw new BadRequest(); } if (!$this->user->isAdmin() && $id !== $this->user->getId()) { throw new Forbidden(); } return $this->service->read($id); } /** * @throws BadRequest * @throws Forbidden * @throws Error * @throws NotFound */ public function postActionGetTwoFactorUserSetupData(Request $request): stdClass { $data = $request->getParsedBody(); $id = $data->id ?? null; if (!$id) { throw new BadRequest("No 'id'."); } if (!$this->user->isAdmin() && $id !== $this->user->getId()) { throw new Forbidden(); } return $this->service->getTwoFactorUserSetupData($id, $data); } /** * @throws BadRequest * @throws Forbidden * @throws NotFound */ public function putActionUpdate(Request $request): stdClass { $id = $request->getRouteParam('id'); $data = $request->getParsedBody(); if (!$id) { throw new BadRequest(); } if (!$this->user->isAdmin() && $id !== $this->user->getId()) { throw new Forbidden(); } return $this->service->update($id, $data); } }