Browse Source

updated Libraries/Aauth & LoginTest

v3-dev
REJack 6 years ago
parent
commit
4ac3c0738b
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 7
      application/Libraries/Aauth.php
  2. 24
      tests/Aauth/Libraries/Aauth/LoginTest.php

7
application/Libraries/Aauth.php

@ -839,6 +839,7 @@ class Aauth
public function isLoggedIn() public function isLoggedIn()
{ {
helper('cookie'); helper('cookie');
if (isset($this->session->get('user')['loggedIn'])) if (isset($this->session->get('user')['loggedIn']))
{ {
return true; return true;
@ -869,7 +870,7 @@ class Aauth
} }
else else
{ {
$loginTokenModel->delete($cookie[0]); $loginTokenModel->deleteExpired($cookie[0]);
delete_cookie('remember'); delete_cookie('remember');
} }
} }
@ -936,7 +937,7 @@ class Aauth
{ {
if ($includeNonFlash) if ($includeNonFlash)
{ {
$flashErrorsOld = $this->session->getFlashdata('errors'); $flashErrorsOld = $this->session->getFlashdata('errors');
$this->flashErrors = array_merge((is_array($flashErrorsOld) ? $flashErrorsOld : []), $this->errors); $this->flashErrors = array_merge((is_array($flashErrorsOld) ? $flashErrorsOld : []), $this->errors);
$this->session->setFlashdata('errors', $this->flashErrors); $this->session->setFlashdata('errors', $this->flashErrors);
} }
@ -1050,7 +1051,7 @@ class Aauth
{ {
if ($includeNonFlash) if ($includeNonFlash)
{ {
$flashInfosOld = $this->session->getFlashdata('infos'); $flashInfosOld = $this->session->getFlashdata('infos');
$this->flashInfos = array_merge((is_array($flashInfosOld) ? $flashInfosOld : []), $this->infos); $this->flashInfos = array_merge((is_array($flashInfosOld) ? $flashInfosOld : []), $this->infos);
$this->session->setFlashdata('infos', $this->flashInfos); $this->session->setFlashdata('infos', $this->flashInfos);
} }

24
tests/Aauth/Libraries/Aauth/LoginTest.php

@ -134,6 +134,7 @@ class LoginTest extends CIDatabaseTestCase
$session->set('user', [ $session->set('user', [
'loggedIn' => true, 'loggedIn' => true,
]); ]);
$this->assertTrue($this->library->isLoggedIn());
helper('text'); helper('text');
$config = new AauthConfig(); $config = new AauthConfig();
@ -149,6 +150,29 @@ class LoginTest extends CIDatabaseTestCase
'expires_at' => date('Y-m-d H:i:s', strtotime('+1 week')), 'expires_at' => date('Y-m-d H:i:s', strtotime('+1 week')),
]); ]);
$this->assertTrue($this->library->isLoggedIn()); $this->assertTrue($this->library->isLoggedIn());
$session->remove('user');
$_COOKIE['remember'] = base64_encode(a) . ';' . $selectorString . ';' . $randomString;
$this->assertFalse($this->library->isLoggedIn());
}
public function testIsLoggedInExpired()
{
helper('text');
$session = $this->getInstance();
$this->library = new Aauth(null, $session);
$config = new AauthConfig();
$randomString = random_string('alnum', 32);
$selectorString = random_string('alnum', 16);
$_COOKIE['remember'] = base64_encode(1) . ';' . $randomString . ';' . $selectorString;
$this->hasInDatabase($config->dbTableLoginTokens, [
'user_id' => 1,
'random_hash' => password_hash($randomString, PASSWORD_DEFAULT),
'selector_hash' => password_hash($selectorString, PASSWORD_DEFAULT),
'expires_at' => date('Y-m-d H:i:s', strtotime('-1 week')),
]);
$this->assertFalse($this->library->isLoggedIn());
} }
public function testLogout() public function testLogout()

Loading…
Cancel
Save