From d0e9f21e1fc54019fe7cff9aa24ccb3e58f634fd Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 Feb 2017 17:35:54 +0200 Subject: [PATCH] registration --- app/library/App/Controllers/UserController.php | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/app/library/App/Controllers/UserController.php b/app/library/App/Controllers/UserController.php index 47a1e07..5860368 100755 --- a/app/library/App/Controllers/UserController.php +++ b/app/library/App/Controllers/UserController.php @@ -36,8 +36,53 @@ class UserController extends CrudResourceController public function register() { - $this->create(); + $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); + $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); + } + + $newItem = $success ? $item : null; + + if (!$newItem) { + return $this->onCreateFailed($item, $data); + } + + die(var_dump($newItem)); + + $primaryKey = $this->getModelPrimaryKey(); + $responseData = $this->getFindData($newItem->$primaryKey); + + $response = $this->getCreateResponse($responseData, $data); + + return $response; } public function whitelist() -- libgit2 0.21.4