Exemplo n.º 1
0
 /**
  * Check if the user is logged in and everything is fine.
  *
  * @return void
  */
 public function checkAuthentication()
 {
     $isLoggedIn = Phprojekt_Auth::isLoggedIn();
     if ($isLoggedIn) {
         // Check the CSRF token
         $this->checkCsrfToken();
     } else {
         // User not logged in, display login page
         // If is a GET, show the index page with isLogged false
         // If is a POST, send message in json format
         if ($this->getRequest()->getActionName() == 'index') {
             $isLoggedIn = false;
             if ($this->getRequest()->getModuleName() != 'Default') {
                 $this->_forward('index', 'Default', 'Default', null);
             }
         } else {
             $this->getResponse()->setRawHeader('HTTP/1.1 401 Authorization Required');
             $this->getResponse()->sendHeaders();
             exit;
         }
     }
     $this->view->clearVars();
     $this->view->isLoggedIn = $isLoggedIn;
     // Setting the domain selection
     $authMode = Phprojekt_Auth::getLoginMode();
     if ($authMode == 'ldap') {
         $conf = Phprojekt::getInstance()->getConfig();
         $ldapOptions = isset($conf->authentication->ldap) ? $conf->authentication->ldap->toArray() : array();
         $domains = array();
         foreach ($ldapOptions as $server => $opts) {
             $serverName = isset($opts['accountDomainNameShort']) ? trim($opts['accountDomainNameShort']) : (isset($opts['accountDomainName']) ? trim($opts['accountDomainName']) : $server);
             $domains[$server] = $serverName;
         }
         if (sizeof($domains) > 0) {
             $this->view->domains = $domains;
         }
     }
 }