/**
  * @runInSeparateProcess
  * @outputBuffering disabled
  */
 public function testProtectedController()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('Xdebug not installed');
     }
     $autoloader = new Autoloader();
     $autoloader->register();
     $autoloader->addNamespaces([['Linna\\FOO', dirname(__DIR__) . '/FOO']]);
     //config options
     $session = new Session();
     $session->start();
     $password = new Password();
     $storedPassword = $password->hash('password');
     //attemp first login
     $login = new Login($session, $password);
     $login->login('root', 'password', $storedUser = '******', $storedPassword, 1);
     $loginLogged = $login->logged;
     $model = new FOOModel();
     $controller1 = new FOOProtectedController($model, $login);
     $controllerTest1 = $controller1->test;
     $login->logout();
     $loginNoLogged = $login->logged;
     ob_start();
     $controller2 = new FOOProtectedController($model, $login);
     $headers_list = xdebug_get_headers();
     ob_end_clean();
     $this->assertEquals(true, $loginLogged);
     $this->assertEquals(false, $loginNoLogged);
     $this->assertEquals(true, $controllerTest1);
     $this->assertEquals(true, in_array('Location: http://localhost', $headers_list));
     $session->destroy();
 }
Esempio n. 2
0
 /**
  * Change user password only after check old password
  *
  * @param string $newPassword New user password
  * @param string $oldPassword Old user password
  *
  * @return bool
  *
  */
 public function chagePassword($newPassword, $oldPassword)
 {
     $passUtil = new Password();
     $hash = $passUtil->hash($newPassword);
     if ($passUtil->verify($oldPassword, $this->password)) {
         $this->password = $hash;
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Try to log the user passed by param, return true if ok else false
  *
  * @param string $user
  * @param string $password
  * @param string $storedUser
  * @param string $storedPassword
  * @param int $storedId
  *
  * @return bool
  */
 public function login(string $user, string $password, string $storedUser = '', string $storedPassword = '', int $storedId = 0) : bool
 {
     if ($user !== $storedUser) {
         return false;
     }
     if (!$this->password->verify($password, $storedPassword)) {
         return false;
     }
     $this->sessionInstance->loginTime = time();
     $this->sessionInstance->login = ['login' => true, 'user_id' => $storedId, 'user_name' => $storedUser];
     $this->sessionInstance->regenerate();
     $this->logged = true;
     return true;
 }