Esempio n. 1
0
 /**
  * Create CAPTCHA token
  *
  * @param  int $reload
  * @return Captcha
  */
 public function createToken($reload = null)
 {
     $sess = Session::getInstance();
     ob_start();
     include __DIR__ . '/../../../phire/view/captcha.phtml';
     $captcha = ob_get_clean();
     // If reload, or captcha token doesn't exist, create new one
     if (null !== $reload || !isset($sess->pop_captcha)) {
         $token = ['captcha' => $captcha, 'value' => Random::create($this->length, Random::ALPHANUM | Random::UPPERCASE), 'expire' => (int) $this->expire, 'start' => time()];
         $sess->pop_captcha = serialize($token);
         // Else, check existing token
     } else {
         $token = unserialize($sess->pop_captcha);
         if ($token['value'] == '') {
             $token = ['captcha' => $captcha, 'value' => Random::create($this->length, Random::ALPHANUM | Random::UPPERCASE), 'expire' => (int) $this->expire, 'start' => time()];
             $sess->pop_captcha = serialize($token);
             // Check to see if the token has expired
         } else {
             if ($token['expire'] > 0) {
                 if ($token['expire'] + $token['start'] < time()) {
                     $token = ['captcha' => $captcha, 'value' => Random::create($this->length, Random::ALPHANUM | Random::UPPERCASE), 'expire' => (int) $this->expire, 'start' => time()];
                     $sess->pop_captcha = serialize($token);
                 }
             }
         }
     }
     $this->token = $token;
     return $this;
 }
Esempio n. 2
0
 /**
  * Send user password reminder notification
  *
  * @param  Table\Users $user
  * @return void
  */
 protected function sendReminder(Table\Users $user)
 {
     $host = Table\Config::findById('domain')->value;
     $domain = str_replace('www.', '', $host);
     $newPassword = Random::create(8, Random::ALPHANUM | Random::LOWERCASE);
     $user->password = (new Bcrypt())->create($newPassword);
     $user->save();
     // Set the recipient
     $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain, 'username' => $user->username, 'password' => $newPassword];
     // Check for an override template
     $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/forgot.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/forgot.txt' : __DIR__ . '/../../view/phire/mail/forgot.txt';
     // Send email verification
     $mail = new Mail($domain . ' - Forgot Password', $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText(file_get_contents($mailTemplate));
     $mail->send();
 }