Commit e95cb5df20a340a4230fc049466bbfdf70f821a3
1 parent
8e3b7275
user registration
Showing
3 changed files
with
45 additions
and
2 deletions
Show diff stats
app/library/App/Controllers/UserController.php
| ... | ... | @@ -41,4 +41,43 @@ class UserController extends CrudResourceController |
| 41 | 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
app/library/App/Resources/UserResource.php
| ... | ... | @@ -39,6 +39,10 @@ class UserResource extends ApiResource { |
| 39 | 39 | 'token' => 'co126bbm40wqp41i3bo7pj1gfsvt9lp6', |
| 40 | 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 | 49 | \ No newline at end of file | ... | ... |