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 ($matches) {
         $error = 'Unauthorized!';
         if ($matches[1]) {
             $error = ucfirst($matches[1]);
         }
         if (!App::getInstance()->getSession()->_login) {
             throw new \Exception($error, 401);
         }
     }
     $adminRegex = '/@admin/';
     preg_match($adminRegex, $doc, $matches);
     if ($matches) {
         if (!SimpleDB::isAdmin()) {
             throw new \Exception("Admin access only!", 401);
         }
     }
     $roleRegex = '/@role\\s*\\("(.+)"\\)/';
     preg_match($roleRegex, $doc, $matches);
     if ($matches[1]) {
         $role = $matches[1];
         if (!SimpleDB::hasRole($role) && !SimpleDB::isAdmin()) {
             $role = ucfirst($role);
             throw new \Exception("{$role} access only!", 401);
         }
     }
 }
Пример #2
0
 public function isModerator()
 {
     return SimpleDB::hasRole('moderator');
 }