Esempio n. 1
0
 public function registerAction()
 {
     return $this->handleRequest(function () {
         $req = new Request();
         if ($req->isPost()) {
             $post = json_decode($req->getRawBody());
             $a = $this->getUserDocument();
             $user = new $a();
             $user->salt = Text::random(Text::RANDOM_ALNUM);
             $user->password = $this->hash($post->password, $user->salt);
             unset($post->password);
             $post = (array) $post;
             foreach ($post as $key => $value) {
                 $user->{$key} = $value;
             }
             $user->save();
             $this->session->set('user', $user);
         } else {
             if ($req->isOptions()) {
                 return '';
             }
         }
         return $this->jsonOutput($user);
     });
 }
Esempio n. 2
0
 /**
  * Gets the parameters, sorted from parent to child
  * @return \stdClass
  * @throws Exception
  */
 private function loadParams()
 {
     if ($this->getRequest()->getRawBody() == '' && empty($this->getRequest()->getPost()) && empty($this->getRequest()->getPut()) && empty($this->getRequest()->getUploadedFiles())) {
         throw new Exception('No Data Passed', 400);
     }
     $bulkCreation = false;
     if (!is_null($this->getRequest()->getJsonRawBody())) {
         $params = $this->getRequest()->getJsonRawBody();
         $delimiter = '.';
         if (is_array($params)) {
             $bulkCreation = true;
         }
     } else {
         if ($this->getRequest()->isPost()) {
             $params = $this->getRequest()->getPost();
         } else {
             $params = $this->getRequest()->getPut();
         }
         $delimiter = '_';
     }
     if ($this->request->getRawBody() != '' && sizeOf($params) == 0 && json_last_error() != JSON_ERROR_NONE) {
         $this->dispatchJsonError();
     }
     if ($bulkCreation) {
         //Bulk Creation
         $outputParams = [];
         foreach ($params as $param) {
             $helper = new SplitHelper($delimiter);
             $outputParams[] = $helper->convert((array) $param);
         }
         $this->setParams($outputParams);
     } else {
         $helper = new SplitHelper($delimiter);
         $this->setParams($helper->convert((array) $params));
     }
 }
Esempio n. 3
0
 public function getRawBody()
 {
     return parent::getRawBody();
 }