/**
  * request
  *
  * @return  bool
  *
  * @throws \Exception
  */
 protected function request()
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         $this->setRedirect($this->router->http('forgot'), Translator::translate('windwalker.user.no.email'));
         return false;
     }
     $view = $this->getView();
     $token = md5($this->app->get('secret') . uniqid() . CryptHelper::genRandomBytes());
     $link = $this->router->http('forgot', array('task' => 'confirm', 'token' => $token), Router::TYPE_FULL);
     $user = User::get(array('email' => $email));
     if ($user->notNull()) {
         $password = new Password();
         $user->reset_token = $password->create($token);
         $user->reset_last = DateTime::create('now', DateTime::TZ_LOCALE)->toSql(true);
         User::save($user);
     }
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $view->setLayout('email')->render();
     // Please send email here.
     // ----------------------------------------------------
     // ----------------------------------------------------
     $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), array('This is test message.', $body));
     return true;
 }
 /**
  * Method to test decrypt().
  *
  * @return void
  *
  * @covers Windwalker\Crypt\Cipher\McryptCipher::decrypt
  */
 public function testDecrypt()
 {
     // Use IV
     $iv = CryptHelper::genRandomBytes(16);
     $data = $this->instance->encrypt('windwalker', $this->key, $iv);
     $ivSize = strlen($iv);
     $iv = substr($data, 0, $ivSize);
     $data = substr($data, $ivSize);
     $data = $this->instance->decrypt($data, $this->key, $iv);
     $this->assertEquals('windwalker', $data);
 }
Exemple #3
0
 /**
  * getToken
  *
  * @param string $data
  * @param string $secret
  *
  * @return  string
  */
 public static function getToken($data = null, $secret = null)
 {
     $secret = $secret ?: Ioc::getConfig()->get('system.secret');
     $data = json_encode($data);
     return md5($secret . $data . uniqid() . CryptHelper::genRandomBytes());
 }