Пример #1
0
 /**
  * Log out the current user.
  *
  * @param string $url     URL to redirect user to after logging out.
  * @param bool   $destroy Should we destroy the session (true) or just reset it
  * (false); destroy is for log out, reset is for expiration.
  *
  * @return string     Redirect URL (usually same as $url, but modified in
  * some authentication modules).
  */
 public function logout($url, $destroy = true)
 {
     // Perform authentication-specific cleanup and modify redirect URL if
     // necessary.
     $url = $this->getAuth()->logout($url);
     // Clear out the cached user object and session entry.
     $this->currentUser = false;
     unset($this->session->userId);
     $this->cookieManager->set('loggedOut', 1);
     // Destroy the session for good measure, if requested.
     if ($destroy) {
         $this->sessionManager->destroy();
     } else {
         // If we don't want to destroy the session, we still need to empty it.
         // There should be a way to do this through Zend\Session, but there
         // apparently isn't (TODO -- do this better):
         $_SESSION = [];
     }
     return $url;
 }
 public function logoutAction()
 {
     $config = new StandardConfig();
     $manager = new SessionManager($config);
     if ($this->getAuthService()->hasIdentity()) {
         $this->getSessionStorage()->forgetMe();
         $this->getAuthService()->clearIdentity();
         $manager->destroy();
         $this->flashmessenger()->addMessage("You've been logout");
     }
     return $this->redirect()->toRoute('manager');
 }
Пример #3
0
 /**
  *
  */
 public function logout()
 {
     $this->authService->clearIdentity();
     $this->sessionManager->destroy(['send_expire_cookie' => true, 'clear_storage' => true]);
 }
Пример #4
0
 public function _init(Dispatcher $dispatcher)
 {
     // 引入Composer,Yaf扩展的配置项yaf.use_spl_autoload务必设置为1
     if (file_exists(ROOT_PATH . '/vendor/autoload.php')) {
         $loader = (include ROOT_PATH . '/vendor/autoload.php');
         //$loader->add("",ROOT_PATH.'/library');
         //$loader->addPsr4("Zend\\",ROOT_PATH.'/library/Zend');
         Registry::set('loader', $loader);
     }
     // 禁止自动渲染
     $dispatcher->autoRender(FALSE);
     // 保存配置
     $this->_config = Application::app()->getConfig();
     Registry::set('config', $this->_config);
     // 报错设置
     if ($this->_config->global->showError) {
         error_reporting(-1);
         ini_set('display_errors', 'On');
     }
     // 加解密
     if (!empty($this->_config->global->key)) {
         Registry::set('enc', function () {
             $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
             $blockCipher->setKey($this->_config->global->key);
             return $blockCipher;
         });
     }
     // 命令行方式,跳过SESSION
     if (!defined("RUN_IN_CLI")) {
         // 保存路径
         $sessionConfig = $this->_config->session->toArray();
         if (isset($sessionConfig['save_path'])) {
             @mkdir($sessionConfig['save_path'], 0777, true);
         }
         // 配置
         $config = new SessionConfig();
         $config->setOptions($sessionConfig);
         // 会话管理器
         $manager = new SessionManager($config);
         // 开启会话
         $manager->start();
         // 验证会话
         $manager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
         if (!$manager->isValid()) {
             $manager->destroy();
             throw new \Exception("会话验证失败");
         }
         // 会话Token
         $default = new Zend\Session\Container();
         if (empty($default->offsetGet('securityToken'))) {
             $default->offsetSet('securityToken', md5(uniqid(rand(), true)));
         }
         // 保存实例
         Registry::set('session', $default);
         Registry::set('sm', $manager);
     }
     // 数据库
     Registry::set('db', function () {
         $mysqlMasterConfig = $this->_config->mysql->master->toArray();
         $adapter = new Adapter($mysqlMasterConfig);
         $connect = $adapter->getDriver()->getConnection();
         for ($i = 0; $i < 5; $i++) {
             if ($connect->isConnected()) {
                 break;
             }
             $connect->connect();
         }
         return $adapter;
     });
     // 邮件
     Registry::set('mail', function () {
         $options = new SmtpOptions($this->_config->smtp->toArray());
         $mail = new SmtpTransport();
         $mail->setOptions($options);
         return $mail;
     });
     // 日志
     Registry::set('logger', function () {
         $logger = new Zend\Log\Logger();
         $writer = new Zend\Log\Writer\Stream($this->_config->log->path . '/' . date("Ymd") . ".log");
         $logger->addWriter($writer);
         return $logger;
     });
 }