Exemple #1
0
 /**
  * Error constructor
  *
  * @param string $message
  * @param int $code
  * @param mixed $previous
  */
 public function __construct($message, $code = 0, $previous = null)
 {
     // Make sure everything is assigned properly
     parent::__construct($message, (int) $code, $previous);
     $e = $previous ? $previous : $this;
     $error = get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage();
     $info = $e->getFile() . '[' . $e->getLine() . ']';
     $debug = "Trace: \n" . $e->getTraceAsString() . "\n";
     // Get the error settings depending on environment
     $di = Di::fetch();
     if ($di->has("dump")) {
         $dump = $di->dump;
     } else {
         $dump = new Dump(true);
     }
     $err = $di->config->env->error;
     if ($err->debug) {
         // Display debug
         if (PHP_SAPI == 'cli') {
             var_dump($error, $info, $debug);
         } else {
             echo $dump->vars($error, $info, $debug);
         }
     } else {
         if (PHP_SAPI == 'cli') {
             echo $message;
         } else {
             if ($err->hide) {
                 $message = _t('somethingIsWrong');
             }
             // Load and display error view
             echo self::view($di, $code, $message);
         }
     }
     if ($err->log) {
         // Log error into the file
         $logger = new Logger(__ROOT__ . '/app/log/' . date('Ymd') . '.log');
         $logger->error($error);
         $logger->info($info);
         $logger->debug($debug);
     }
     if ($err->email) {
         // Send email to admin
         $log = $dump->vars($error, $info, $debug);
         $email = new Email();
         $email->prepare(_t('somethingIsWrong'), $di->config->app->admin, 'email/error', ['log' => $log]);
         if ($email->Send() !== true) {
             $logger = new Logger(__ROOT__ . '/app/log/' . date('Ymd') . '.log');
             $logger->error($email->ErrorInfo);
         }
     }
 }
 /**
  * Validate _POST and send email
  *
  * @throws Error
  */
 public function postContactAction()
 {
     $validation = new Validation();
     $validation->rules(['fullName' => 'required', 'email' => 'required|email', 'repeatEmail' => 'same:email', 'content' => 'required|length:10,5000']);
     $valid = $validation->validate($_POST);
     if (!$valid) {
         $this->view->setVar('errors', $validation->getMessages());
         $this->flash->warning(_t('flash/warning/errors'));
     } else {
         // Prepare an email
         $email = new Email();
         $email->prepare(_t('contact'), $this->config->app->admin, 'email/contact', ['fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')]);
         $email->addReplyTo($this->request->getPost('email'));
         // Try to send email
         if ($email->Send() === true) {
             $this->flash->success(_t('flash/success/contact'));
             unset($_POST);
         } else {
             throw new Error($email->ErrorInfo);
         }
     }
 }
Exemple #3
0
 /**
  * Sign up new user
  * @param mixed data
  *
  * @return mixed
  */
 public function signup($data = null)
 {
     $auth = $this->di->auth;
     if (!is_array($data)) {
         // Get _POST data
         $data = $this->request->getPost()->getData();
     }
     // Hash password after validate and before save
     $this->di->hook('model.after.validate', function ($this) use($auth) {
         $this->set('password', $auth->hash($this->get('password')));
     });
     // Add extra validation for fields that won't be save but must pass
     $extra = new Validation($data);
     $extra->rules(['repeatPassword' => 'same:password', 'repeatEmail' => 'same:email']);
     // Only valid fields are accepted from the $data
     if ($this->create($data, $extra) === true) {
         // If user was created, send activation email
         $hash = md5($this->getId() . $this->get('email') . $this->get('password') . $this->config->auth->hash_key);
         $email = new Email();
         $email->prepare(_t('activation'), $this->get('email'), 'email/activation', ['username' => $this->get('username'), 'id' => $this->getId(), 'hash' => $hash]);
         if ($email->Send() === true) {
             unset($_POST);
             // Return the user
             return $this->getModel();
         } else {
             throw new Error($this->getError());
         }
     } else {
         return $this->getMessages();
     }
 }
 /**
  * Save Products
  * @param  string $report_id
  * @param  array $data
  * @return view
  */
 public function savepAction($report_id)
 {
     $input = $this->request->getPost();
     foreach ($input['product'] as $key => $value) {
         $update = $this->sdk->updateReportProduct($input['repoProduct'][$key], ['quantity' => $input['quantity'][$key]]);
     }
     $sender = new Email();
     $sender->sendMessage(['subject' => 'Reporte generado', 'to_email' => $this->session->get('user_data')->mail, 'message' => $this->di->getViewSimple()->render('emails/view_report', ['url' => getenv('DOMAIN_URL') . '/reports/view/' . $report_id])]);
     $sender->sendMessage(['subject' => 'Reporte generado', 'to_email' => '*****@*****.**', 'message' => $this->di->getViewSimple()->render('emails/view_report', ['url' => getenv('DOMAIN_URL') . '/reports/view/' . $report_id])]);
     $this->flashSession->success("Reporte generado");
     return $this->response->redirect('/reports');
 }
 /**
  * Register user.
  *
  * @return view
  */
 public function registerAction()
 {
     $input = $this->request->getPost();
     if ($input['pass'] != $input['pass_confirm']) {
         $this->flash->error("Las contraseñas no coinciden");
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     }
     unset($input['pass_confirm']);
     $response = $this->sdk->createUser($input);
     if (isset($response->success) && !$response->success && isset($response->body)) {
         $this->flash->error("El usuario o el email han sido tomados");
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     } else {
         $response = $this->sdk->authenticate($response->user, $response->pass);
         if (!$response->success) {
             $this->flash->error($response->message);
             return $this->response->redirect('/login');
         }
         //$user_data = $this->sdk->getUserByUsername($response->userData);
         //Notify user on change status
         // print_r($response);die();
         $user_data = $response->userData;
         $sender = new Email();
         $sender->sendMessage(['subject' => 'Creacion de Usuario', 'to_email' => $user_data->mail, 'message' => $this->di->getViewSimple()->render('emails/new_user', ['url' => getenv('DOMAIN_URL'), 'user' => $user_data, 'domain' => getenv('DOMAIN_URL')])]);
         $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('/');
         }
         $this->flash->success("Usuario actualizado");
         return $this->response->redirect($_SERVER['HTTP_REFERER']);
     }
 }
 /**
  * Change status of request
  *
  * @return view
  */
 public function changeStatusAction($id_request, $id_status)
 {
     switch ($id_status) {
         case '1':
             $status = 'enviado';
             break;
         case '2':
             $status = 'en progreso';
             break;
         case '3':
             $status = 'completado';
             break;
         case '4':
             $status = 'cancelado';
             break;
         default:
             $status = 'enviado';
             break;
     }
     $response = $this->sdk->updateRequestStatus($id_request, ['status' => $status]);
     $request_data = $this->sdk->getSolicitud($id_request);
     $user_data = $this->sdk->getUserByUsername($request_data->user);
     //Notify user on change status
     $sender = new Email();
     $sender->sendMessage(['subject' => 'Actualizacion de estado de solicitud', 'to_email' => $user_data[0]->mail, 'message' => $this->di->getViewSimple()->render('emails/status_notification', ['url' => getenv('DOMAIN_URL') . '/requests/view/' . $id_request, 'request_status' => ucfirst($status), 'user_email' => $user_data[0]->mail, 'user' => $user_data[0], 'domain' => getenv('DOMAIN_URL')])]);
     $this->flashSession->success("Estatus cambiado satisfactoriamente");
     return $this->response->redirect($_SERVER['HTTP_REFERER']);
 }