Exemplo n.º 1
0
 public function runLogic(Trace $trace, HttpConnection $connection)
 {
     $session = $this->context->getSessionStorage();
     $loginManager = new LoginManager($session, $this->context->getRequest());
     $server = $this->getServer();
     $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap($server->getServerName()));
     $action = $this->context->getRequest()->getParameter('action', 'studium.MojeTerminyHodnotenia');
     $response = $this->context->getResponse();
     if ($action == 'logout') {
         $loginManager->logout($serverConnection);
         FajrUtils::redirect(array(), 'index.php');
         exit;
     } else {
         if ($action == 'termsOfUse') {
             // TODO(anty): refactor this
             $response->setTemplate('termsOfUse');
             return;
         }
     }
     if ($loginManager->shouldLogin()) {
         $factory = $this->injector->getInstance('LoginFactory.class');
         $loginManager->login($trace->addChild("Logging in..."), $server, $factory, $serverConnection);
         $loggedIn = false;
         // login makes redirect on success
     } else {
         $loggedIn = $loginManager->isLoggedIn($serverConnection);
     }
     if ($loggedIn) {
         $controllerInjector = new Injector(array(new ControllerInjectorModule($serverConnection, $server, $session)));
         $mainScreen = $controllerInjector->getInstance('AIS2MainScreen.class');
         if (($aisVersion = $session->read('ais/aisVersion')) == null) {
             $aisVersion = $mainScreen->getAisVersion($trace->addChild('Get AIS version'));
             $session->write('ais/aisVersion', $aisVersion);
         }
         if (($aisApps = $session->read('ais/aisApps')) == null) {
             $aisApps = $mainScreen->getAllAvailableApplications($trace->addChild('Get all applications'));
             $session->write('ais/aisApps', $aisApps);
         }
         if (($userName = $session->read('ais/aisUserName')) == null) {
             $userName = $mainScreen->getFullUserName($trace->addChild('Get user name'));
             $session->write('ais/aisUserName', $userName);
         }
         $response->set('aisVersion', $aisVersion);
         $response->set('aisVersionIncompatible', !($aisVersion >= regression\VersionRange::getMinVersion() && $aisVersion <= regression\VersionRange::getMaxVersion()));
         $response->set('aisUserName', $userName);
         $controller = new DispatchController($controllerInjector, $this->injector->getParameter('controller.dispatchMap'));
         $response->set("action", $action);
         $controller->invokeAction($trace, $action, $this->context);
         $response->set('statistics', $this->statistics);
     } else {
         $server = $this->getServer();
         switch ($server->getLoginType()) {
             case 'password':
                 $response->setTemplate('welcome');
                 break;
             case 'cosign':
                 $response->setTemplate('welcomeCosign');
                 break;
             case 'cosignproxy':
                 $response->setTemplate('welcomeCosignProxy');
                 break;
             case 'nologin':
                 $response->setTemplate('welcomeDemo');
                 break;
             default:
                 throw new Exception("Invalid type of login");
         }
     }
 }
Exemplo n.º 2
0
 public function runLogic(Trace $trace)
 {
     $session = $this->context->getSessionStorage();
     $loginManager = new LoginManager($session, $this->context->getRequest(), $this->context->getResponse());
     // we are going to log in and  we need a clean session.
     // This needs to be done before a connection
     // is created, because we pass cookie file name
     // that contains session_id into AIS2CurlConnection
     if ($loginManager->shouldLogin()) {
         $session->regenerate(true);
     }
     $connection = $this->provideConnection();
     $server = $this->getServer();
     $serverConnection = new AIS2ServerConnection($connection, new AIS2ServerUrlMap($server->getServerName()));
     $action = $this->context->getRequest()->getParameter('action', 'studium.MojeTerminyHodnotenia');
     $response = $this->context->getResponse();
     if ($action == 'logout') {
         try {
             $loginManager->logout($serverConnection);
         } catch (LoginException $e) {
             $this->setException($e);
         }
     } else {
         if ($action == 'termsOfUse') {
             // TODO(anty): refactor this
             $response->setTemplate('termsOfUse');
             return;
         } else {
             if ($loginManager->shouldLogin()) {
                 $factory = $this->injector->getInstance('LoginFactory.class');
                 try {
                     $loginManager->login($trace->addChild("Logging in..."), $server, $factory, $serverConnection);
                 } catch (LoginException $e) {
                     $this->setException($e);
                     try {
                         $loginManager->logout($trace, $serverConnection);
                     } catch (LoginException $e) {
                         // do nothing
                     }
                 }
             } else {
                 if ($loginManager->isLoggedIn($serverConnection)) {
                     $response->set('loggedIn', true);
                     $controllerInjector = new Injector(array(new ControllerInjectorModule($serverConnection, $server, $session, $this->config)), $this->config->get(FajrConfigOptions::DEBUG_EXCEPTION_SHOWSTACKTRACE));
                     $mainScreen = $controllerInjector->getInstance('AIS2MainScreen.class');
                     if (($aisVersion = $session->read('ais/aisVersion')) == null) {
                         $aisVersion = $mainScreen->getAisVersion($trace->addChild('Get AIS version'));
                         $session->write('ais/aisVersion', $aisVersion);
                     }
                     if (($aisApps = $session->read('ais/aisApps')) == null) {
                         $aisModules = array('SP', 'LZ', 'ES', 'ST', 'RH', 'UB', 'AS', 'RP');
                         $aisApps = $mainScreen->getAllAvailableApplications($trace->addChild('Get all applications'), $aisModules);
                         $session->write('ais/aisApps', $aisApps);
                     }
                     if (($userName = $session->read('ais/aisUserName')) == null) {
                         $userName = $mainScreen->getFullUserName($trace->addChild('Get user name'));
                         $session->write('ais/aisUserName', $userName);
                     }
                     $response->set('aisVersion', $aisVersion);
                     $response->set('aisVersionIncompatible', !($aisVersion >= regression\VersionRange::getMinVersion() && $aisVersion <= regression\VersionRange::getMaxVersion()));
                     $response->set('aisUserName', $userName);
                     $controller = new DispatchController($controllerInjector, $this->injector->getParameter('controller.dispatchMap'));
                     $response->set("action", $action);
                     $controller->invokeAction($trace, $action, $this->context);
                     $response->set('statistics', $this->statistics);
                 } else {
                     $server = $this->getServer();
                     switch ($server->getLoginType()) {
                         case 'password':
                             $response->setTemplate('welcome');
                             break;
                         case 'cosign':
                             $response->setTemplate('welcomeCosign');
                             break;
                         case 'cosignproxy':
                             $response->setTemplate('welcomeCosignProxy');
                             break;
                         case 'nologin':
                             $response->setTemplate('welcomeDemo');
                             break;
                         default:
                             throw new Exception("Invalid type of login");
                     }
                 }
             }
         }
     }
 }