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 register() { $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); $item = $this->createModelInstance(); /** ****************************/ $user = new User(); $user->password = 'test332332212'; $user->save(); die(var_dump($user)); echo $user->id; $project = new Project(); $project->name = 'test33233222'; $project->save(); echo $project->id; die(); /** **********************/ $newItem = $this->createItem($item, $data); if (!$newItem) { return $this->onCreateFailed($item, $data); } //$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; } // public function whitelist() // { // return [ // 'username', // 'password', // 'email' // ]; // } protected function getModelPrimaryKey() { return 'id'; } protected function transformPostDataValue($key, $value, $data) { if ($key == 'password') { return $this->security->hash($value); } else { return $value; } } }