public function __construct($databaseConnection, $sessionName, $tableName = 'sessions', $lifeTime = 3600, $path = null, $domain = null, $secure = false)
 {
     parent::__construct($databaseConnection);
     $this->sessionName = $sessionName;
     $this->tableName = $tableName;
     $this->lifeTime = $lifeTime;
     $this->path = $path;
     $this->domain = $domain;
     $this->secure = $secure;
     $this->sessionId = $_COOKIE[$sessionName];
     if (rand(0, 50) == 1) {
         $this->_clearExpiredSessions();
     }
     if (strlen($this->sessionId) < 32) {
         $this->_startNewSession();
     } else {
         if (!$this->_validateSession()) {
             $this->_startNewSession();
         }
     }
 }
 private function ValidateAuthorization($doc)
 {
     $doc = strtolower($doc);
     $notLoggedRegex = '/@notlogged/';
     preg_match($notLoggedRegex, $doc, $matches);
     if ($matches) {
         if (App::getInstance()->getSession()->_login) {
             throw new \Exception("Already logged in!", 400);
         }
     }
     $authorizeRegex = '/@authorize(?:\\s+error:\\("(.+)"\\))?/';
     preg_match($authorizeRegex, $doc, $matches);
     if (isset($matches) && $matches != null) {
         $error = 'Unauthorized!';
         if (isset($matches[1]) && $matches[1] != null) {
             $error = ucfirst($matches[1]);
         }
         if (!App::getInstance()->getSession()->_login) {
             throw new \Exception($error, 401);
         }
     }
     $adminRegex = '/@admin/';
     preg_match($adminRegex, $doc, $matches);
     if ($matches) {
         if (!SimpleDatabase::isAdmin()) {
             throw new \Exception("Admin access only!", 401);
         }
     }
     $roleRegex = '/@role\\s*\\("(.+)"\\)/';
     preg_match($roleRegex, $doc, $matches);
     if (isset($matches[1]) && $matches[1] != null) {
         $role = $matches[1];
         if (!SimpleDatabase::hasRole($role) && !SimpleDatabase::isAdmin()) {
             $role = ucfirst($role);
             throw new \Exception("{$role} access only!", 401);
         }
     }
 }
Example #3
0
 public function isModerator()
 {
     return SimpleDatabase::hasRole('moderator');
 }