createResourceResponse($this->userService->getDetails()); } public function authenticate() { $username = $this->request->getUsername(); $password = $this->request->getPassword(); $session = $this->authManager->loginWithUsernamePassword(\App\Auth\UsernameAccountType::NAME, $username, $password); $transformer = new \App\Transformers\UserTransformer; $transformer->setModelClass('App\Model\User'); $user = $this->createItemResponse(\App\Model\User::findFirst($session->getIdentity()), $transformer); $response = [ 'token' => $session->getToken(), 'expires' => $session->getExpirationTime(), 'user' => $user ]; return $this->createArrayResponse($response, 'data'); } public function whitelist() { return [ 'firstName', 'lastName', 'password' ]; } public function registration() { $this->beforeHandle(); $this->beforeHandleWrite(); $this->beforeHandleCreate(); $data = $this->getPostedData(); if (!$data || count($data) == 0) { return $this->onNoDataProvided(); } if (!$this->postDataValid($data, false)) { return $this->onDataInvalid($data); } if (!$this->saveAllowed($data) || !$this->createAllowed($data)) { return $this->onNotAllowed(); } $data = $this->transformPostData($data); $newItem = new User(); $map = $newItem->columnMap(); foreach ($data as $key => $value) { if (in_array($key, $map)) $newItem->$key = $value; } if (!$newItem) { return $this->onCreateFailed($newItem, $data); } $newItem->save(); $last_id = $newItem->getWriteConnection()->lastInsertId(); $responseData = $this->getFindData($last_id); $response = $this->getCreateResponse($responseData, $data); $this->afterHandleCreate($newItem, $data, $response); $this->afterHandleWrite(); $this->afterHandle(); return $response; } // protected function transformPostData($data) // { // $result = []; // // foreach ($data as $key => $value) { // $result[$key] = $this->transformPostDataValue($key, $value, $data); // } // // return $result; // } protected function transformPostDataValue($key, $value, $data) { if ($key == 'pass') { return $this->security->hash($value); } else { return $value; } } }