Commit e95cb5df20a340a4230fc049466bbfdf70f821a3

Authored by Alex Savenko
1 parent 8e3b7275

user registration

app/library/App/Controllers/UserController.php
@@ -41,4 +41,43 @@ class UserController extends CrudResourceController @@ -41,4 +41,43 @@ class UserController extends CrudResourceController
41 'password' 41 'password'
42 ]; 42 ];
43 } 43 }
  44 +
  45 + public function registration() {
  46 +
  47 + $data = $this->getPostedData();
  48 +
  49 + if (!$data || count($data) == 0) {
  50 + return $this->onNoDataProvided();
  51 + }
  52 +
  53 + if (!$this->postDataValid($data, false)) {
  54 + return $this->onDataInvalid($data);
  55 + }
  56 +
  57 + if (!$this->saveAllowed($data) || !$this->createAllowed($data)) {
  58 + return $this->onNotAllowed();
  59 + }
  60 +
  61 + $data = $this->transformPostData($data);
  62 +
  63 + $item = $this->createModelInstance();
  64 +
  65 + $newItem = $this->createItem($item, $data);
  66 +
  67 + if (!$newItem) {
  68 + return $this->onCreateFailed($item, $data);
  69 + }
  70 +
  71 + $primaryKey = $this->getModelPrimaryKey();
  72 + $responseData = $this->getFindData($newItem->$primaryKey);
  73 +
  74 + $response = $this->getCreateResponse($responseData, $data);
  75 +
  76 + $this->afterHandleCreate($newItem, $data, $response);
  77 + $this->afterHandleWrite();
  78 + $this->afterHandle();
  79 +
  80 + return $response;
  81 +
  82 + }
44 } 83 }
app/library/App/Model/Project.php
@@ -23,7 +23,7 @@ class Project extends \App\Mvc\DateTrackingModel { @@ -23,7 +23,7 @@ class Project extends \App\Mvc\DateTrackingModel {
23 public function columnMap() 23 public function columnMap()
24 { 24 {
25 return parent::columnMap() + [ 25 return parent::columnMap() + [
26 - //'id' => 'id', 26 + 'id' => 'id',
27 'name' => 'name', 27 'name' => 'name',
28 'user_id' => 'user_id' 28 'user_id' => 'user_id'
29 ]; 29 ];
app/library/App/Resources/UserResource.php
@@ -39,6 +39,10 @@ class UserResource extends ApiResource { @@ -39,6 +39,10 @@ class UserResource extends ApiResource {
39 'token' => 'co126bbm40wqp41i3bo7pj1gfsvt9lp6', 39 'token' => 'co126bbm40wqp41i3bo7pj1gfsvt9lp6',
40 'expires' => 1451139067 40 'expires' => 1451139067
41 ]) 41 ])
42 - ); 42 + )
  43 + ->endpoint(ApiEndpoint::post('/registration', 'registration'))
  44 + ->deny(AclRoles::AUTHORIZED)
  45 + ->description('Registration')
  46 + ;
43 } 47 }
44 } 48 }
45 \ No newline at end of file 49 \ No newline at end of file