Exemplo n.º 1
0
 /**
  * Create  requests section
  *
  * @return view
  */
 public function createAction()
 {
     $data = $this->request->getPost();
     $data['user'] = $this->session->get('user_data')->user;
     $response = $this->sdk->createReport($data);
     foreach ($data['items'] as $key => $value) {
         $this->sdk->createReportProduct(['user_id' => $data['user'], 'quantity' => 1, 'product_id' => $value, 'report_id' => $response->_id]);
     }
     if (isset($response->success) && !$response->success && isset($response->body)) {
         $errors = [];
         $str_error = '';
         if (isset($response->body->errmsg)) {
             $str_error = "Error: " . $response->body->errmsg;
         } else {
             foreach ($response->body->errors as $key => $value) {
                 $errors[] = $key;
             }
             $str_error = ucfirst($response->body->message) . ". Formato invalido: " . Validator::stringFromArray($errors);
         }
         $this->flashSession->error((string) $str_error);
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     } else {
         return $this->response->redirect('/reports/products/' . $response->_id);
     }
 }
Exemplo n.º 2
0
 /**
  * Login process
  *
  * @return mixed
  */
 public function loginAction()
 {
     if (!$this->request->isPost()) {
         $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
         return $this->view->pick('secure/login');
     }
     $validate_input = Validator::requiredKeys($this->request->getPost(), ['username' => '', 'password' => '']);
     if (!$validate_input->ok) {
         $this->flash->error(Validator::stringFromArray($validate_input->errors, 'Te falta: '));
         return $this->response->redirect('/login');
     }
     $response = $this->sdk->authenticate($validate_input->data->username, $validate_input->data->password);
     if (!$response->success) {
         $this->flash->error($response->message);
         return $this->response->redirect('/login');
     }
     $this->session->set('identity', $response->userData->_id);
     $this->session->set('user_data', $response->userData);
     $this->session->set('user_session_token', $response->token);
     if ($this->isLogged()) {
         return $this->response->redirect('/');
     }
     return $this->response->redirect('/login');
 }
Exemplo n.º 3
0
 /**
  * Create  requests section
  *
  * @return view
  */
 public function createAction()
 {
     $request_data = (array) $this->session->get('request_process');
     $response = $this->sdk->createRequest($request_data);
     if (isset($response->success) && !$response->success && isset($response->body)) {
         $errors = [];
         $str_error = '';
         if (isset($response->body->errmsg)) {
             $str_error = "Error: " . $response->body->errmsg;
         } else {
             foreach ($response->body->errors as $key => $value) {
                 $errors[] = $key;
             }
             $str_error = ucfirst($response->body->message) . ". Formato invalido en: " . Validator::stringFromArray($errors);
         }
         $this->flashSession->error((string) $str_error);
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     } else {
         $sender = new Email();
         $sender->sendMessage(['subject' => 'Solicitud generada', 'to_email' => $this->session->get('user_data')->mail, 'message' => $this->di->getViewSimple()->render('emails/new_request_user_notification', ['url' => getenv('DOMAIN_URL') . '/requests/view/' . $response->_id])]);
         $sender->sendMessage(['subject' => 'Solicitud generada', 'to_email' => '*****@*****.**', 'message' => $this->di->getViewSimple()->render('emails/new_request_admin_notification', ['url' => getenv('DOMAIN_URL') . '/requests/view/' . $response->_id])]);
         $this->flashSession->success("Solicitud enviada");
         $this->session->remove('request_process');
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     }
 }
Exemplo n.º 4
0
 /**
  * Save user.
  *
  * @return view
  */
 public function saveAction($id)
 {
     $response = $this->sdk->updateUser($id, $this->request->getPost());
     if (isset($response->success) && !$response->success && isset($response->body)) {
         $errors = [];
         $str_error = '';
         if (isset($response->body->errmsg)) {
             $str_error = "Error: " . $response->body->errmsg;
         } else {
             foreach ($response->body->errors as $key => $value) {
                 $errors[] = $key;
             }
             $str_error = ucfirst($response->body->message) . ". Te falta: " . Validator::stringFromArray($errors);
         }
         $this->flash->error((string) $str_error);
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     } else {
         $this->flash->success("Usuario actualizado");
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     }
 }