Пример #1
0
 /**
  * Log message into file, notify the admin on stagging/production
  *
  * @package     las
  * @version     1.0
  *
  * @param mixed $messages messages to log
  */
 public static function log($messages)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     if ($config->app->env == "development") {
         foreach ($messages as $key => $message) {
             echo Dump::one($message, $key);
         }
         exit;
     } else {
         $logger = new \Phalcon\Logger\Adapter\File(ROOT_PATH . '/app/common/logs/' . date('Ymd') . '.log', array('mode' => 'a+'));
         $log = '';
         foreach ($messages as $key => $message) {
             if (in_array($key, array('alert', 'debug', 'error', 'info', 'notice', 'warning'))) {
                 $logger->{$key}($message);
             } else {
                 $logger->log($message);
             }
             $log .= Dump::one($message, $key);
         }
         if ($config->app->env != "testing") {
             $email = new Email();
             $email->prepare(__('Something is wrong!'), $config->app->admin, 'error', array('log' => $log));
             if ($email->Send() !== true) {
                 $logger->log($email->ErrorInfo);
             }
         }
         $logger->close();
         return $log;
     }
 }
Пример #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();
         }
     }
 }