예제 #1
0
파일: index.php 프로젝트: nbtetreault/igo
 $app = new \Phalcon\Mvc\Micro();
 $app->setDI($di);
 $app->get('/configuration/{configuration}', function ($configuration) use($di, $app) {
     $configArray = explode(".", $configuration);
     $configKey = $configArray[0];
     $encoding = "json";
     if (count($configArray) === 2) {
         $encoding = $configArray[1];
     }
     // Gerer le cas où on appelle une configuration inexistante et où il y aurait une erreur dans la configuration.
     if (isset($di->getConfig()->configurations[$configKey])) {
         $xmlPath = $di->getConfig()->configurations[$configKey];
     } else {
         $xmlPath = $di->getConfig()->configurationsDir . $configKey . '.xml';
     }
     if (!file_exists($xmlPath) && !curl_url_exists($xmlPath)) {
         $app->response->setStatusCode(404, "Not Found");
         $error = new stdClass();
         $error->error = "La configuration « {$configuration} » n'existe pas!";
         $app->response->send();
         die(json_encode($error));
     }
     if ($encoding === "json") {
         $app->response->setContentType('application/json; charset=UTF-8')->sendHeaders();
         if (file_exists($xmlPath)) {
             $element = simplexml_load_file($xmlPath, 'SimpleXMLElement', LIBXML_NOCDATA);
         } else {
             $element = simplexml_load_string(curl_file_get_contents($xmlPath), 'SimpleXMLElement', LIBXML_NOCDATA);
         }
         if ($element->getName() === "navigateur") {
             //Gerer le cas des couches seulement avec un Id
예제 #2
0
 public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $authentificationModule = $this->getDI()->get("authentificationModule");
     if ($authentificationModule == null) {
         return;
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $config = $this->getDI()->get("config");
     if ($controller === "connexion" || $controller === "error") {
         $config = $this->getDI()->get("config");
         $this->getDI()->get("view")->setViewsDir($config->application->services->viewsDir);
     } else {
         if ($controller === "igo" && ($action === "configuration" || $action === "index")) {
             $configuration = $this->obtenirConfiguration($action, $dispatcher);
             if (isset($this->getDi()->getConfig()->configurations[$configuration])) {
                 $file = $this->getDi()->getConfig()->configurations[$configuration];
             } else {
                 $file = $this->getDi()->getConfig()->configurationsDir . $configuration . '.xml';
             }
             if (!file_exists($file) && !curl_url_exists($file)) {
                 return $this->forwardToErrorPage();
             }
             if ($this->estAuthentificationRequise($configuration) && !$this->estAnonyme() && !$this->estAuthentifie()) {
                 return $this->forwardToLoginPage();
             } else {
                 if ($this->estAuthentificationRequise($configuration) && $this->estRoleSelectionneRequis() && !$this->estRoleSelectionne()) {
                     return $this->forwardToRolePage();
                 } else {
                     if (!$this->estAuthentificationRequise($configuration) && !$this->estAuthentifie()) {
                         $authentificationModule = $this->getDI()->get("authentificationModule");
                         if (!$this->session->has("info_utilisateur")) {
                             $this->session->set("info_utilisateur", new SessionController());
                         }
                         $configuration = $this->getDI()->get("config");
                         if ($configuration->offsetExists("database")) {
                             // Si la BD n'existe pas dans la config on n'ajoute pas de profil et on se base sur le xml
                             if ($this->estRoleSelectionneRequis()) {
                                 $this->session->get("info_utilisateur")->profilActif = IgoProfil::findFirst("nom = '{$configuration->application->authentification->nomProfilAnonyme}'")->id;
                             } else {
                                 if (isset($configuration->application->authentification->nomProfilAnonyme)) {
                                     $this->session->get("info_utilisateur")->profils = IgoProfil::find("nom = '{$configuration->application->authentification->nomProfilAnonyme}'");
                                 }
                             }
                         }
                         $this->session->get("info_utilisateur")->estAnonyme = true;
                     } else {
                         if ($this->estRoleSelectionneRequis() && !$this->estRoleSelectionne()) {
                             return $this->forwardToRolePage();
                         }
                     }
                 }
             }
             if ($this->estAnonyme() && isset($config->application->authentification->permettreAccesAnonyme) && !$config->application->authentification->permettreAccesAnonyme) {
                 return $this->forwardToUnauthorizedPage();
             }
         } else {
             if ($controller == "igo" && ($action == "contexte" || $action == "couche" || $action == "groupe")) {
                 if (!$this->estAnonyme() && !$this->estAuthentifie()) {
                     return $this->forwardToLoginPage();
                 } else {
                     if ($this->estRoleSelectionneRequis() && !$this->estRoleSelectionne()) {
                         return $this->forwardToRolePage();
                     }
                 }
                 if ($this->estAnonyme() && isset($config->application->authentification->permettreAccesAnonyme) && !$config->application->authentification->permettreAccesAnonyme) {
                     return $this->forwardToUnauthorizedPage();
                 }
             }
         }
     }
 }