diff --git a/classes/Security.php b/classes/Security.php index 02767c5..859543b 100644 --- a/classes/Security.php +++ b/classes/Security.php @@ -225,73 +225,11 @@ class Security { return $_SESSION['__pickles']['security']['level']; } - // Hits the database to determine the user's level + // Used to hit the database to determine the user's level, found it + // to be overkill and just opted for a simple logout. else { - // Checks the session cache instead of hitting the database - if (isset($_SESSION['__pickles']['security']['user_id'], self::$cache[(int)$_SESSION['__pickles']['security']['user_id']])) - { - return self::$cache[(int)$_SESSION['__pickles']['security']['user_id']]; - } - else - { - // Pulls the config and defaults where necessary - $config = Config::getInstance(); - - if ($config->security === false) - { - $config = []; - } - else - { - $config = $config->security; - } - - $defaults = [ - 'login' => 'login', - 'model' => 'User', - 'column' => 'level', - ]; - - foreach ($defaults as $variable => $value) - { - if (!isset($config[$variable])) - { - $config[$variable] = $value; - } - } - - // Uses the model to pull the user's access level - $class = $config['model']; - $model = new $class([ - 'fields' => $config['column'], - 'conditions' => [ - 'id' => (int)$_SESSION['__pickles']['security']['user_id'], - ], - ]); - - if ($model->count() == 0) - { - Security::logout(); - } - else - { - $constant = 'SECURITY_LEVEL_' . $model->record[$config['column']]; - - if (defined($constant)) - { - $constant = constant($constant); - - self::$cache[(int)$_SESSION['__pickles']['security']['user_id']] = $constant; - - return $constant; - } - else - { - throw new Exception('Security level constant is not defined'); - } - } - } + Security::logout(); } } diff --git a/tests/classes/SecurityTest.php b/tests/classes/SecurityTest.php index 3fca4b5..de30480 100644 --- a/tests/classes/SecurityTest.php +++ b/tests/classes/SecurityTest.php @@ -100,7 +100,6 @@ class SecurityTest extends PHPUnit_Framework_TestCase $this->assertFalse(Security::isLevel(SECURITY_LEVEL_USER)); } - /* public function testIsLevelDB() { $config = Config::getInstance(); @@ -127,6 +126,7 @@ class SecurityTest extends PHPUnit_Framework_TestCase 'namespace' => '', ], ], + 'security' => ['model' => 'MockUserModel'], ]; $model = new MockUserModel(); @@ -141,9 +141,14 @@ class SecurityTest extends PHPUnit_Framework_TestCase Security::login(1, 10, 'USER'); - //$this->assertTrue(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN])); + unset( + $_SESSION['__pickles']['security']['token'], + $_COOKIE['pickles_security_token'], + $_SESSION['__pickles']['security']['level'] + ); + + $this->assertFalse(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN])); } - */ } ?> diff --git a/tests/schema.sql b/tests/schema.sql index 4ee97f5..6ad0317 100644 --- a/tests/schema.sql +++ b/tests/schema.sql @@ -23,7 +23,7 @@ DROP TABLE IF EXISTS users; CREATE TABLE `users` ( `id` int(1) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(100) COLLATE utf8_unicode_ci NOT NULL, - `role` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'USER', + `level` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'USER', `created_id` int(1) unsigned DEFAULT NULL, `created_at` datetime NOT NULL, `updated_id` int(1) unsigned DEFAULT NULL,