diff --git a/application/Libraries/Aauth.php b/application/Libraries/Aauth.php index 9cc3441..199e058 100644 --- a/application/Libraries/Aauth.php +++ b/application/Libraries/Aauth.php @@ -250,6 +250,8 @@ class Aauth { $userModel = new UserModel(); $user = $userModel->limit($limit, $offset); + + $userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login'); // eanbool $group_par = null, if (is_null($includeBanneds)) @@ -343,6 +345,8 @@ class Aauth $userModel = new UserModel(); $userVariableModel = new UserVariableModel(); + $userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login'); + if (! $userId) { $userId = $this->session->id; @@ -396,6 +400,32 @@ class Aauth return false; } + /** + * Is banned + * + * @param integer $userId User id + * + * @return boolean + */ + public function isBanned(int $userId) + { + $userModel = new UserModel(); + + if (! $userId) + { + $userId = $this->session->id; + } + + if (! $userModel->existsById($userId)) + { + $this->error(lang('Aauth.notFoundUser')); + + return false; + } + + return $userModel->isBanned($userId); + } + /** * Ban User * diff --git a/phpunit.xml b/phpunit.xml index aeddaaa..1897d87 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,9 +21,11 @@ - ./application/Libraries - ./application/Models + ./application/Models/Aauth + ./application/Language/*/Aauth ./application/Config/Aauth.php + ./application/Config/Aauth.php + ./application/Libraries/Aauth.php diff --git a/tests/Aauth/Libraries/Aauth/UserTest.php b/tests/Aauth/Libraries/Aauth/UserTest.php new file mode 100644 index 0000000..cf0d357 --- /dev/null +++ b/tests/Aauth/Libraries/Aauth/UserTest.php @@ -0,0 +1,103 @@ +library = new Aauth(null, true); + $userPre = $this->library->getUser(2); + $this->library->updateUser(2, 'user1@example.com', 'password987654', 'user1'); + $user = $this->library->getUser(2); + $this->assertNotEquals($userPre['email'], $user['email']); + $this->assertNotEquals($userPre['username'], $user['username']); + $this->library->updateUser(2, null, null, 'user1'); + $userAfter = $this->library->getUser(2); + $this->assertEquals($user['username'], $userAfter['username']); + } + + public function testDeleteUser() + { + $this->library = new Aauth(null, true); + $users = $this->library->listUsers(); + $this->assertCount(2, $users); + $this->library->deleteUser(2); + $users = $this->library->listUsers(); + $this->assertCount(1, $users); + $this->assertFalse($this->library->deleteUser(99)); + } + + public function testListUsers() + { + $this->library = new Aauth(null, true); + $users = $this->library->listUsers(); + $this->assertCount(2, $users); + } + + public function testGetUser() + { + $this->library = new Aauth(null, true); + $user = $this->library->getUser(1); + $this->assertEquals('1', $user['id']); + $this->assertEquals('admin', $user['username']); + $this->assertEquals('admin@example.com', $user['email']); + } + + public function testGetUserUserVars() + { + $this->library = new Aauth(null, true); + $user = $this->library->getUser(1, true); + $this->assertInternalType('array', $user['variables']); + } + + public function testGetUserId() + { + $this->library = new Aauth(null, true); + $userIdEmail = $this->library->getUserId('admin@example.com'); + $this->assertEquals('1', $userIdEmail); + // $userIdNone = $this->library->getUserId(); + // $this->assertEquals('1', $userIdNone); + } + + public function testBanUser() + { + $this->library = new Aauth(null, true); + $this->assertFalse($this->library->isBanned(1)); + $this->library->banUser(1); + $this->assertTrue($this->library->isBanned(1)); + } + + public function testUnbanUser() + { + $this->library = new Aauth(null, true); + $this->library->banUser(1); + $this->assertTrue($this->library->isBanned(1)); + $this->library->unbanUser(1); + $this->assertFalse($this->library->isBanned(1)); + } +}