Exemplo n.º 1
0
 /**
  * Contact Action
  *
  * @package     las
  * @version     1.0
  */
 public function contactAction()
 {
     $this->tag->setTitle(__('Contact'));
     if ($this->request->isPost() === true) {
         $validation = new \Las\Extension\Validation();
         $validation->add('fullName', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('content', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('content', new \Phalcon\Validation\Validator\StringLength(array('max' => 5000, 'min' => 10)));
         $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf());
         $validation->add('email', new \Phalcon\Validation\Validator\Email());
         $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email')));
         $validation->setLabels(array('fullName' => __('Full name'), 'content' => __('Content'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email')));
         $messages = $validation->validate($_POST);
         if (count($messages)) {
             $this->view->setVar('errors', $validation->getMessages());
             $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
         } else {
             $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Message was sent"));
             $email = new \Las\Library\Email();
             $email->prepare(__('Contact'), $this->config->app->admin, 'contact', array('fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')));
             $email->addReplyTo($this->request->getPost('email'));
             if ($email->Send() === true) {
                 unset($_POST);
             } else {
                 \Las\Bootstrap::log($email->ErrorInfo);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Sign up User method
  *
  * @version     1.0
  */
 public function signup($role = 'login')
 {
     $validation = new \Las\Extension\Validation();
     $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('username', new \Las\Extension\Uniqueness(array('model' => '\\Las\\Models\\Users')));
     $validation->add('username', new \Phalcon\Validation\Validator\StringLength(array('min' => 4, 'max' => 24)));
     $validation->add('password', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('repeatPassword', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'password')));
     $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('email', new \Phalcon\Validation\Validator\Email());
     $validation->add('email', new \Las\Extension\Uniqueness(array('model' => '\\Las\\Models\\Users')));
     $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email')));
     $validation->setLabels(array('username' => __('Username'), 'password' => __('Password'), 'repeatPassword' => __('Repeat password'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email')));
     $messages = $validation->validate($_POST);
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->username = $this->getDI()->getShared('request')->getPost('username');
         $this->password = Auth::instance()->hash($this->getDI()->getShared('request')->getPost('password'));
         $this->email = $this->getDI()->getShared('request')->getPost('email');
         $this->logins = 0;
         if ($this->create() === true) {
             if ($role == 'admin') {
                 return $this;
             } else {
                 $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key);
                 $email = new Email();
                 $email->prepare(__('Activation'), $this->getDI()->getShared('request')->getPost('email'), 'activation', array('username' => $this->getDI()->getShared('request')->getPost('username'), 'hash' => $hash));
                 if ($email->Send() === true) {
                     unset($_POST);
                     return true;
                 } else {
                     \Las\Bootstrap::log($email->ErrorInfo);
                     return false;
                 }
             }
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Write method - add/edit the tariff
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new \Las\Extension\Validation();
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['min' => 3, 'max' => 32]));
     $validation->add('amount', new Validator\PresenceOf());
     $validation->add('amount', new Validator\Regex(['pattern' => '/\\d+(\\.\\d{2})?/']));
     $validation->add('priority', new Validator\Between(['minimum' => 10, 'maximum' => 99]));
     $validation->add('downloadRate', new Validator\Between(['minimum' => 0, 'maximum' => Tariffs::rate('download')]));
     $validation->add('downloadCeil', new Validator\Between(['minimum' => 0, 'maximum' => Networks::ceil('download')]));
     $validation->add('uploadRate', new Validator\Between(['minimum' => 0, 'maximum' => Tariffs::rate('upload')]));
     $validation->add('uploadCeil', new Validator\Between(['minimum' => 0, 'maximum' => Networks::ceil('upload')]));
     $validation->add('limit', new Validator\Regex(['allowEmpty' => true, 'pattern' => '/\\d+/']));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Tariffs::status()]));
     $validation->setLabels(['name' => __('Name'), 'amount' => __('Amount'), 'priority' => __('Priority'), 'downloadRate' => __('Download rate'), 'downloadCeil' => __('Download ceil'), 'uploadRate' => __('Upload rate'), 'uploadCeil' => __('Upload ceil'), 'limit' => __('Limit'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->amount = $this->request->getPost('amount');
         $this->priority = $this->request->getPost('priority', 'int');
         $this->downloadRate = $this->request->getPost('downloadRate', 'float');
         $this->downloadCeil = $this->request->getPost('downloadCeil', 'float');
         $this->uploadRate = $this->request->getPost('uploadRate', 'float');
         $this->uploadCeil = $this->request->getPost('uploadCeil', 'float');
         $this->limit = $this->request->getPost('limit', 'int', null, ture);
         $this->description = $this->request->getPost('description');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Write method - add/edit the client
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new \Las\Extension\Validation();
     $validation->add('fullName', new Validator\PresenceOf());
     $validation->add('fullName', new Validator\StringLength(['min' => 3, 'max' => 32]));
     $validation->add('address', new Validator\StringLength(['max' => 256]));
     $validation->add('tariff', new Validator\PresenceOf());
     $validation->add('tariff', new Validator\InclusionIn(['domain' => Arr::from_model($this->tariffs, NULL, 'id')]));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Clients::status()]));
     $validation->setLabels(['fullName' => __('Full name'), 'address' => __('Address'), 'tariff' => __('Tariff'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->fullName = $this->request->getPost('fullName', 'string');
         $this->address = $this->request->getPost('address', 'string');
         $this->tariff_id = $this->request->getPost('tariff', 'int');
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }