Commit cdd122fc8496885d4955bda1a13e791ad5a5b720

Authored by Alex Savenko
1 parent 6ae0cce2

user registration

Showing 1 changed file with 38 additions and 1 deletions   Show diff stats
app/library/App/Controllers/UserController.php
... ... @@ -44,7 +44,44 @@ class UserController extends CrudResourceController
44 44  
45 45 public function registration() {
46 46  
47   - return $this->createResponse($this->create());
  47 + $this->beforeHandle();
  48 + $this->beforeHandleWrite();
  49 + $this->beforeHandleCreate();
  50 +
  51 + $data = $this->getPostedData();
  52 +
  53 + if (!$data || count($data) == 0) {
  54 + return $this->onNoDataProvided();
  55 + }
  56 +
  57 + if (!$this->postDataValid($data, false)) {
  58 + return $this->onDataInvalid($data);
  59 + }
  60 +
  61 + if (!$this->saveAllowed($data) || !$this->createAllowed($data)) {
  62 + return $this->onNotAllowed();
  63 + }
  64 +
  65 + $data = $this->transformPostData($data);
  66 +
  67 + $item = $this->createModelInstance();
  68 +
  69 + $newItem = $this->createItem($item, $data);
  70 +
  71 + if (!$newItem) {
  72 + return $this->onCreateFailed($item, $data);
  73 + }
  74 +
  75 + $primaryKey = $this->getModelPrimaryKey();
  76 + $responseData = $this->getFindData($newItem->$primaryKey);
  77 +
  78 + $response = $this->getCreateResponse($responseData, $data);
  79 +
  80 + $this->afterHandleCreate($newItem, $data, $response);
  81 + $this->afterHandleWrite();
  82 + $this->afterHandle();
  83 +
  84 + return $response;
48 85  
49 86 }
50 87  
... ...