Esempio n. 1
0
 /**
  * Resend activation email
  *
  * @param $user
  * @param bool|FALSE $email_address
  * @return bool
  * @throws \Exception
  * @throws \phpmailerException
  */
 public function resend($user, $email_address = FALSE)
 {
     $re_user = self::findFirst(array('conditions' => "id = '{$user}'"));
     $isAlreadyUnconfirmed = $this::getUserRoles($user, 'unconfirmed');
     if (!$isAlreadyUnconfirmed) {
         $this::setUserRole($user, 'unconfirmed');
     }
     if ($email_address) {
         $send_to = $email_address;
         // if user changed email address update user email address in database
         $re_user->email = $email_address;
         if ($re_user->update() !== TRUE) {
             \Baseapp\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     } else {
         $send_to = $re_user->email;
     }
     $hash = md5($user . $send_to . $re_user->password . $this->getDI()->getShared('config')->auth->hash_key);
     $email = new Email();
     $email->prepare(__('Activation'), $send_to, 'activation', array('username' => $re_user->username, 'hash' => $hash));
     if ($email->Send() === TRUE) {
         return TRUE;
     }
 }
Esempio n. 2
0
 /**
  * Log message into file, notify the admin on stagging/production
  *
  * @param mixed $messages messages to log
  */
 public static function log($messages)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     $dump = new Dump();
     if ($config->app->env == "development") {
         foreach ($messages as $key => $message) {
             echo $dump->one($message, $key);
         }
         exit;
     } else {
         $logger = new \Phalcon\Logger\Adapter\File(APP_PATH . '/app/common/logs/' . date('Ymd') . '.log', array('mode' => 'a+'));
         $log = '';
         if (is_array($messages) || $messages instanceof \Countable) {
             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);
             }
         } else {
             $logger->log($messages);
             $log .= $dump->one($messages);
         }
         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();
     }
 }
Esempio n. 3
0
 /**
  * Sign up User method
  *
  * @version     2.0
  */
 public function signup()
 {
     $validation = new \Baseapp\Extension\Validation();
     $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf());
     $validation->add('username', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\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 \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\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->request->getPost('username');
         $this->password = $this->getDI()->getShared('auth')->hash($this->request->getPost('password'));
         $this->email = $this->request->getPost('email');
         $this->logins = 0;
         if ($this->create() === true) {
             $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key);
             $email = new Email();
             $email->prepare(__('Activation'), $this->request->getPost('email'), 'activation', array('username' => $this->request->getPost('username'), 'hash' => $hash));
             if ($email->Send() === true) {
                 unset($_POST);
                 return $this;
             } else {
                 \Baseapp\Bootstrap::log($email->ErrorInfo);
                 return false;
             }
         } else {
             \Baseapp\Bootstrap::log($this->getMessages());
             return false;
         }
     }
 }