From e95cb5df20a340a4230fc049466bbfdf70f821a3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Feb 2017 14:05:59 +0200 Subject: [PATCH] user registration --- app/library/App/Controllers/UserController.php | 39 +++++++++++++++++++++++++++++++++++++++ app/library/App/Model/Project.php | 2 +- app/library/App/Resources/UserResource.php | 6 +++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/library/App/Controllers/UserController.php b/app/library/App/Controllers/UserController.php index d388366..ef0e8c9 100755 --- a/app/library/App/Controllers/UserController.php +++ b/app/library/App/Controllers/UserController.php @@ -41,4 +41,43 @@ class UserController extends CrudResourceController '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); + } + + $primaryKey = $this->getModelPrimaryKey(); + $responseData = $this->getFindData($newItem->$primaryKey); + + $response = $this->getCreateResponse($responseData, $data); + + $this->afterHandleCreate($newItem, $data, $response); + $this->afterHandleWrite(); + $this->afterHandle(); + + return $response; + + } } diff --git a/app/library/App/Model/Project.php b/app/library/App/Model/Project.php index 54d3fe0..bd78b43 100644 --- a/app/library/App/Model/Project.php +++ b/app/library/App/Model/Project.php @@ -23,7 +23,7 @@ class Project extends \App\Mvc\DateTrackingModel { public function columnMap() { return parent::columnMap() + [ - //'id' => 'id', + 'id' => 'id', 'name' => 'name', 'user_id' => 'user_id' ]; diff --git a/app/library/App/Resources/UserResource.php b/app/library/App/Resources/UserResource.php index 2779e9e..d6185a6 100755 --- a/app/library/App/Resources/UserResource.php +++ b/app/library/App/Resources/UserResource.php @@ -39,6 +39,10 @@ class UserResource extends ApiResource { 'token' => 'co126bbm40wqp41i3bo7pj1gfsvt9lp6', 'expires' => 1451139067 ]) - ); + ) + ->endpoint(ApiEndpoint::post('/registration', 'registration')) + ->deny(AclRoles::AUTHORIZED) + ->description('Registration') + ; } } \ No newline at end of file -- libgit2 0.21.4