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() { $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); $item = $this->createModelInstance(); $newItem = $this->createItem($item, $data); if (!$newItem) { return $this->onCreateFailed($item, $data); } return $data; $primaryKey = $this->getModelPrimaryKey(); $responseData = $this->getFindData($newItem->$primaryKey); $response = $this->getCreateResponse($responseData, $data); $this->afterHandleCreate($newItem, $data, $response); $this->afterHandleWrite(); $this->afterHandle(); return $response; } protected function createItem(Model $item, $data) { $this->beforeAssignData($item, $data); $item->assign($data, null, $this->whitelistCreate()); $this->afterAssignData($item, $data); $this->beforeSave($item); $this->beforeCreate($item); $success = $item->create(); if ($success) { $this->afterCreate($item); $this->afterSave($item); } return $success ? $item : null; } }