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(); $newItem = $this->createItem($item, $data); $messages = $newItem->getMessages(); foreach ($messages as $message) { echo $message, "\n"; } if (!$newItem) { return $this->onCreateFailed($item, $data); } die(var_dump($newItem)); $primaryKey = $this->getModelPrimaryKey(); $responseData = $this->getFindData($newItem->$primaryKey); $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 getFindData($id) { $phqlBuilder = $this->phqlQueryParser->fromQuery($this->query, $this->getResource()); $phqlBuilder ->andWhere('[' . $this->getResource()->getModel() . '].' . $this->getModelPrimaryKey() . ' = :id:', ['id' => $id]) ->limit(1); $this->modifyReadQuery($phqlBuilder); $this->modifyFindQuery($phqlBuilder, $id); $results = $phqlBuilder->getQuery()->execute(); return count($results) >= 1 ? $results->getFirst() : null; } }