コード例 #1
0
ファイル: CSRF.php プロジェクト: svetlinyotov/SSFrameWork
 public function generate()
 {
     $token = Common::generateToken();
     if (!is_string($this->_session->getSession()->XSRF_TOKEN)) {
         $this->_session->getSession()->XSRF_TOKEN = $token;
     }
 }
コード例 #2
0
ファイル: Auth.php プロジェクト: svetlinyotov/SSFrameWork
 public function byId($id)
 {
     $token = Common::generateToken();
     Session::getInstance()->getSession()->user_token = $token;
     $this->sql("UPDATE users SET access_token= ? WHERE id = ?", [$token, $id]);
     return true;
 }
コード例 #3
0
ファイル: App.php プロジェクト: svetlinyotov/SSFrameWork
 public function displayError($error)
 {
     if ($error == 0) {
         $error = 500;
     }
     try {
         $view = View::getInstance();
         $view->display('errors.' . $error);
     } catch (\Exception $exc) {
         Common::headerStatus($error);
         echo '<h1>View errors.' . $error . ' not found</h1>';
         exit;
     }
 }
コード例 #4
0
ファイル: Route.php プロジェクト: svetlinyotov/SSFrameWork
 /**
  * Find route in route tree structure.
  *
  * @param $method
  * @return array
  * @throws \Exception
  */
 public function getURI($method = null)
 {
     //$uri = "/".substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME']) + 1)."/";
     $uri = $_SERVER['REQUEST_URI'];
     if ($this->routesTree == null) {
         $this->routesTree = $this->parseRoutes(self::$rawRoutes);
     }
     $search = $this->normalize($uri);
     $node = $this->routesTree;
     $params = [];
     //loop every segment in request url, compare it, collect parameters names and values
     foreach ($search as $v) {
         if (isset($node[$v['use']])) {
             $node = $node[$v['use']];
         } elseif (isset($node['*'])) {
             $node = $node['*'];
             $params[$node['name']] = $v['name'];
         } elseif (isset($node['?'])) {
             $node = $node['?'];
             $params[$node['name']] = $v['name'];
         } else {
             foreach (self::$rawRoutes as $route) {
                 if ($node['exec']['method'][$method] == array_values($route['method'])[0]) {
                     throw new \Exception('Route for uri: ' . $uri . ' was not found');
                 }
             }
         }
     }
     //check for route with optional parameters that are not in request url until valid action is found
     while (!isset($node['exec']) && isset($node['?'])) {
         $node = $node['?'];
     }
     if (isset($node['exec'])) {
         if (!isset($node['exec']['method'][$method]) && !isset($node['exec']['method']['any'])) {
             throw new \Exception('Method: ' . $method . ' is not allowed for this route');
         }
         $this->controller = Common::str_lreplace('Controller', '', explode("@", $node['exec']['method'][$method])[0]);
         $this->method = explode("@", $node['exec']['method'][$method])[1];
         $this->params = $params;
     }
     $this->row = self::$rawRoutes;
     //throw new \Exception('Route for uri: ' . $uri . ' was not found');
 }