Esempio n. 1
0
 public function routerShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
 {
     //不需要权限验证的模块
     $no_require = array('Login' => null);
     //不需要管理员权限的模块
     $admin_require = array('Log' => null, 'Orders' => null, 'Accountgroup' => null, 'Index' => null);
     $is_admin = Yaf\Session::getInstance()->get('is_admin');
     //权限控制
     if (in_array($request->getControllerName(), array_keys($no_require))) {
         return;
     }
     if (!in_array($request->getControllerName(), array_keys($admin_require)) && $is_admin !== '1') {
         $request->setModuleName('Index');
         $request->setControllerName('Login');
         $request->setActionName('get');
         echo 3;
         die;
         return;
     }
     if (!in_array($request->getControllerName(), array_keys($admin_require)) && $is_admin === '0') {
         $request->setModuleName('Index');
         $request->setControllerName('Error');
         $request->setActionName('auth');
         return;
     }
 }
Esempio n. 2
0
 /**
  * Initialize layout and session.
  *
  * In this method can be initialized anything that could be usefull for 
  * the controller.
  *
  * @return void
  */
 public function init()
 {
     // Set the layout.
     $this->getView()->setLayout($this->layout);
     //Set session.
     $this->session = Yaf\Session::getInstance();
     // Assign session to views too.
     $this->getView()->session = $this->session;
     // Assign application config file to this controller
     $this->config = Yaf\Application::app()->getConfig();
     // Assign config file to views
     $this->getView()->config = $this->config;
 }
Esempio n. 3
0
 public function postAction()
 {
     $password = $this->getRequest()->getPost('password');
     $username = $this->getRequest()->getPost('username');
     if (!empty($password) && !empty($username)) {
         $user_dao = new UserDao();
         if ($user_dao->login($username, $password)) {
             Yaf\Session::getInstance()->start();
             Yaf\Session::getInstance()->set('is_admin', $user_dao->getIsAdmin());
             $this->redirect('/');
         } else {
             $this->redirect('/login');
         }
     }
 }
Esempio n. 4
0
 public function init()
 {
     // Set the layout.
     $this->getView()->setLayout($this->layout);
     //Set session.
     $this->session = Yaf\Session::getInstance();
     // Assign session to views too.
     $this->getView()->session = $this->session;
     // Assign application config file to this controller
     $this->_config = Yaf\Application::app()->getConfig();
     // Assign config file to views
     $this->getView()->config = $this->_config;
     $this->getView()->module = $this->getRequest()->getModuleName();
     $this->getView()->controller = $this->getRequest()->getControllerName();
     $this->getView()->action = $this->getRequest()->getActionName();
     $this->_entity = Yaf\Registry::get('entityManager');
 }
Esempio n. 5
0
 public function init()
 {
     // Set the layout. 判断是否ajax请求
     /*
     * 原生js 发送ajax请求时加上header
     *  var xmlhttp=new XMLHttpRequest(); 
        xmlhttp.open("GET","test.php",true); 
        xmlhttp.setRequestHeader("X-Requested-With","XMLHttpRequest"); 
        xmlhttp.send();
     */
     if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") {
         // ajax 请求的处理方式
     } else {
         // 正常请求的处理方式
         $this->getView()->setLayout($this->layout);
     }
     //Set session.
     $this->session = Yaf\Session::getInstance();
     // Assign session to views too.
     $this->getView()->session = $this->session;
     // Assign application config file to this controller
     $this->_config = Yaf\Application::app()->getConfig();
     self::$_widget_config = Yaf\Application::app()->getConfig();
     // Assign config file to views
     $this->getView()->config = $this->_config;
     $this->getView()->module = $this->getRequest()->getModuleName();
     $this->getView()->controller = $this->getRequest()->getControllerName();
     $this->getView()->action = $this->getRequest()->getActionName();
     self::$module = $this->getRequest()->getModuleName();
     self::$controller = $this->getRequest()->getControllerName();
     self::$action = $this->getRequest()->getActionName();
     //title
     $this->getView()->title = $this->_config['application']['title'] . ' - ' . $this->getRequest()->getControllerName();
     //伪静态后缀
     $this->getView()->url_suffix = $this->_config['application']['url_suffix'];
     self::$widgetView = Yaf\Registry::get("widgetView");
     // Set the template_url 设置模版
     //如果默认的module为nomodule 即无module状态,设置theme url
     if (strtolower($this->getRequest()->getModuleName()) == $this->_config->application->dispatcher->defaultModule) {
         $this->getView()->setScriptPath($this->_config->application->view->path);
     }
 }
 /**
  * Creates a random token, ancodes it with Base64 and stores it to session
  *
  * @return string The authenticity token string.
  */
 protected function auth_token()
 {
     $session = Yaf\Session::getInstance();
     $session->auth_token = $session->auth_token ?: base64_encode(sha1(uniqid(rand(), true)));
     return $session->auth_token;
 }