From 0b53af35215368cd9c9ab0fef42c1716196c232c Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Wed, 28 Aug 2019 22:58:09 -0500 Subject: [PATCH] Get our tests passing again. --- src/Authentication/AuthenticationBase.php | 2 +- src/Authentication/LocalAuthenticator.php | 16 ++++++++-------- src/Config/Services.php | 2 +- ... => 2017-11-20-223112_create_auth_tables.php} | 2 +- src/Entities/User.php | 2 +- tests/authentication/LocalAuthTest.php | 1 + 6 files changed, 13 insertions(+), 12 deletions(-) rename src/Database/Migrations/{20171120223112_create_auth_tables.php => 2017-11-20-223112_create_auth_tables.php} (99%) diff --git a/src/Authentication/AuthenticationBase.php b/src/Authentication/AuthenticationBase.php index 16ca2d7e..69cdbf10 100644 --- a/src/Authentication/AuthenticationBase.php +++ b/src/Authentication/AuthenticationBase.php @@ -136,7 +136,7 @@ public function isLoggedIn(): bool // Store our current user object $this->user = $this->userModel->find($userID); - return true; + return $this->user instanceof User; } return false; diff --git a/src/Authentication/LocalAuthenticator.php b/src/Authentication/LocalAuthenticator.php index 14369d15..7080dfd9 100644 --- a/src/Authentication/LocalAuthenticator.php +++ b/src/Authentication/LocalAuthenticator.php @@ -29,14 +29,14 @@ public function attempt(array $credentials, bool $remember = null): bool } if ($this->user->isBanned()) - { - // Always record a login attempt, whether success or not. - $ipAddress = Services::request()->getIPAddress(); - $this->recordLoginAttempt($credentials['email'], $ipAddress, $this->user->id ?? null, false); - - $this->user = null; - return false; - } + { + // Always record a login attempt, whether success or not. + $ipAddress = Services::request()->getIPAddress(); + $this->recordLoginAttempt($credentials['email'], $ipAddress, $this->user->id ?? null, false); + + $this->user = null; + return false; + } return $this->login($this->user, $remember); } diff --git a/src/Config/Services.php b/src/Config/Services.php index 9a41744e..a2948b2a 100644 --- a/src/Config/Services.php +++ b/src/Config/Services.php @@ -17,7 +17,7 @@ public static function authentication(string $lib = 'local', Model $userModel=nu { return self::getSharedInstance('authentication', $lib, $userModel, $loginModel); } - + // config() checks first in app/Config $config = config('Auth'); diff --git a/src/Database/Migrations/20171120223112_create_auth_tables.php b/src/Database/Migrations/2017-11-20-223112_create_auth_tables.php similarity index 99% rename from src/Database/Migrations/20171120223112_create_auth_tables.php rename to src/Database/Migrations/2017-11-20-223112_create_auth_tables.php index 3b336863..c2af4b49 100644 --- a/src/Database/Migrations/20171120223112_create_auth_tables.php +++ b/src/Database/Migrations/2017-11-20-223112_create_auth_tables.php @@ -2,7 +2,7 @@ use CodeIgniter\Database\Migration; -class Migration_create_auth_tables extends Migration +class CreateAuthTables extends Migration { public function up() { diff --git a/src/Entities/User.php b/src/Entities/User.php index fe0b00c9..4a3a79c7 100644 --- a/src/Entities/User.php +++ b/src/Entities/User.php @@ -131,7 +131,7 @@ public function unBan() */ public function isBanned(): bool { - return $this->attributes['status'] === 'banned'; + return isset($this->attributes['status']) && $this->attributes['status'] === 'banned'; } /** diff --git a/tests/authentication/LocalAuthTest.php b/tests/authentication/LocalAuthTest.php index f6509d00..8f8e040c 100644 --- a/tests/authentication/LocalAuthTest.php +++ b/tests/authentication/LocalAuthTest.php @@ -88,6 +88,7 @@ public function testValidateSuccess() public function testCheckNotRemembered() { + $_SESSION = []; $user = $this->createUser(); $this->assertFalse($this->auth->check());