function beforeFilter()
 {
     //
     // Zmena jazyka
     //
     if (isset($_GET['language'])) {
         switch ($_GET['language']) {
             case 'sk':
                 $this->Session->write('Config.language', 'sk');
                 break;
             case 'en':
                 $this->Session->write('Config.language', 'en');
                 break;
         }
     }
     // default language
     if (!$this->Session->read('Config.language')) {
         $this->Session->write('Config.language', 'sk');
     }
     //
     // overi ci je pripojena databaza !!!
     //
     ob_start();
     $db =& ConnectionManager::getDataSource('default');
     if (empty($db->connection)) {
         $php_errors = @ob_get_clean();
         $this->viewPath = 'errors';
         $this->set('host', $db->config['host']);
         $this->set('user', $db->config['login']);
         $this->set('php_errors', $php_errors);
         $this->render('db_connection_failed', 'error');
         exit;
     }
     ob_end_clean();
     //
     // inicializuje session a login
     //
     $this->Login->init();
     //
     // overi uzivatel ma pravo na vybranu stranku
     //
     foreach ($this->required_clearances as $c) {
         if (!$this->Login->check($c)) {
             //
             // TODO (aby pouzivatel po prihlaseni pokracoval na povodnej stranke):
             // - uloz do session momentalnu adresu
             // - a po uspresnom prihlaseni na nu sprav redirect
             //
             $this->My->setInfo(__("ERROR_ACCESS_DENIED", true));
             //
             // presmeruje view do adresara login a vyrenderuje akciu index (pre prihlasenie)
             $this->set("body", $this->requestAction('/login/index', array('return')));
             $this->viewPath = 'login';
             $this->render('access_denied');
             exit;
         }
     }
 }
예제 #2
0
 /**
  * over ci ma naozaj prihlasi
  */
 function testLogin()
 {
     // odhlas ak nahodou je pri
     $this->auth->init();
     // over ze nie je prihlaseny
     $this->assertFalse($this->auth->isLogged());
     // presunie sa do login_history
     $this->assertTrue($this->auth->login('test', 'test'));
     $this->assertTrue($this->auth->login('test', 'test'));
     // users online
     $this->assertTrue($this->auth->isOnlineUsername('test'));
     $this->assertFalse($this->auth->isOnlineUsername('test2'));
     $this->assertFalse($this->auth->isOnlineUsername('testnonexists'));
     $this->assertTrue($this->auth->isOnline(1));
     $this->assertFalse($this->auth->isOnline(845546465));
     // last history
     $lastLogged = $this->auth->lastLogged();
     $this->assertEqual($lastLogged['ip'], $this->auth->Ip());
     // zo session
     $this->assertNotNull($this->auth->fullname());
     $this->assertNotNull($this->auth->username());
     $this->assertNotNull($this->auth->user_id());
     // logout
     $this->assertTrue($this->auth->logout());
     // over odhlasenie
     $this->assertFalse($this->auth->isLogged());
 }