diff --git a/README.md b/README.md index 85437895..8f75dcdd 100644 --- a/README.md +++ b/README.md @@ -191,13 +191,6 @@ The following options are available: - **password_cost** - This should be an integer between 4 and 31. The number represents the base-2 logarithm of the iteration count used for hashing. Default is `10` (about 10 hashes per second on an i5). -- **enable_user_state** - Boolean value, enable user state usage. Should user's - state be used in the registration/login process? -- **default_user_state** - Integer value, default user state upon registration. - What state user should have upon registration? -- **allowed_login_states** - Array value, states which are allowing user to login. - When user tries to login, is his/her state one of the following? Include null if - you want user's with no state to login as well. Changing Registration Captcha Element ------------------------------------- diff --git a/data/schema.ibmdb2.sql b/data/schema.ibmdb2.sql index e6ca77b3..4381a96d 100644 --- a/data/schema.ibmdb2.sql +++ b/data/schema.ibmdb2.sql @@ -4,6 +4,5 @@ CREATE TABLE user username VARCHAR(255) DEFAULT NULL UNIQUE, email VARCHAR(255) DEFAULT NULL UNIQUE, display_name VARCHAR(50) DEFAULT NULL, - password VARCHAR(128) NOT NULL, - state SMALLINT + password VARCHAR(128) NOT NULL ) diff --git a/data/schema.mysql.sql b/data/schema.mysql.sql index 225ab6ee..92a206ed 100644 --- a/data/schema.mysql.sql +++ b/data/schema.mysql.sql @@ -4,6 +4,5 @@ CREATE TABLE `user` `username` VARCHAR(255) DEFAULT NULL UNIQUE, `email` VARCHAR(255) DEFAULT NULL UNIQUE, `display_name` VARCHAR(50) DEFAULT NULL, - `password` VARCHAR(128) NOT NULL, - `state` SMALLINT UNSIGNED + `password` VARCHAR(128) NOT NULL ) ENGINE=InnoDB CHARSET="utf8"; diff --git a/data/schema.pgsql.sql b/data/schema.pgsql.sql index 8fd397a9..72588a62 100644 --- a/data/schema.pgsql.sql +++ b/data/schema.pgsql.sql @@ -5,7 +5,6 @@ CREATE TABLE public.user email character varying(255) DEFAULT NULL UNIQUE, display_name character varying(50) DEFAULT NULL, password character varying(128) NOT NULL, - state smallint, CONSTRAINT user_pkey PRIMARY KEY (user_id), CONSTRAINT user_username_key UNIQUE (username), diff --git a/data/schema.sql b/data/schema.sql index 2780cb6f..18573aab 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -4,6 +4,5 @@ CREATE TABLE user username VARCHAR(255) DEFAULT NULL UNIQUE, email VARCHAR(255) DEFAULT NULL UNIQUE, display_name VARCHAR(50) DEFAULT NULL, - password VARCHAR(128) NOT NULL, - state SMALLINT + password VARCHAR(128) NOT NULL ) ENGINE=InnoDB; diff --git a/data/schema.sqlite.sql b/data/schema.sqlite.sql index 5aad8f11..0493235e 100644 --- a/data/schema.sqlite.sql +++ b/data/schema.sqlite.sql @@ -4,6 +4,5 @@ CREATE TABLE user username VARCHAR(255) DEFAULT NULL UNIQUE, email VARCHAR(255) DEFAULT NULL UNIQUE, display_name VARCHAR(50) DEFAULT NULL, - password VARCHAR(128) NOT NULL, - state SMALLINT + password VARCHAR(128) NOT NULL ); diff --git a/src/ZfcUser/Authentication/Adapter/Db.php b/src/ZfcUser/Authentication/Adapter/Db.php index 3b59202a..dfcf7301 100644 --- a/src/ZfcUser/Authentication/Adapter/Db.php +++ b/src/ZfcUser/Authentication/Adapter/Db.php @@ -85,16 +85,6 @@ public function authenticate(AuthenticationEvent $event) return false; } - if ($this->getOptions()->getEnableUserState()) { - // Don't allow user to login if state is not in allowed list - if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) { - $event->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED) - ->setMessages(array('A record with the supplied identity is not active.')); - $this->setSatisfied(false); - return false; - } - } - $cryptoService = $this->getHydrator()->getCryptoService(); if (!$cryptoService->verify($credential, $userObject->getPassword())) { // Password does not match diff --git a/src/ZfcUser/Entity/User.php b/src/ZfcUser/Entity/User.php index c8fc9f53..e43405ea 100644 --- a/src/ZfcUser/Entity/User.php +++ b/src/ZfcUser/Entity/User.php @@ -29,11 +29,6 @@ class User implements UserInterface */ protected $password; - /** - * @var int - */ - protected $state; - /** * Get id. * @@ -143,26 +138,4 @@ public function setPassword($password) $this->password = $password; return $this; } - - /** - * Get state. - * - * @return int - */ - public function getState() - { - return $this->state; - } - - /** - * Set state. - * - * @param int $state - * @return UserInterface - */ - public function setState($state) - { - $this->state = (int) $state; - return $this; - } } diff --git a/src/ZfcUser/Entity/UserInterface.php b/src/ZfcUser/Entity/UserInterface.php index afa9ae95..e509528e 100644 --- a/src/ZfcUser/Entity/UserInterface.php +++ b/src/ZfcUser/Entity/UserInterface.php @@ -38,11 +38,4 @@ public function getDisplayName(); * @return string password */ public function getPassword(); - - /** - * Get state. - * - * @return int - */ - public function getState(); } diff --git a/src/ZfcUser/Options/ModuleOptions.php b/src/ZfcUser/Options/ModuleOptions.php index 7bd123fc..ff43093e 100644 --- a/src/ZfcUser/Options/ModuleOptions.php +++ b/src/ZfcUser/Options/ModuleOptions.php @@ -41,21 +41,6 @@ class ModuleOptions extends AbstractOptions implements UserControllerOptionsInte */ protected $loginAfterRegistration = true; - /** - * @var int - */ - protected $enableUserState = false; - - /** - * @var int - */ - protected $defaultUserState = 1; - - /** - * @var Array - */ - protected $allowedLoginStates = array( null, 1 ); - /** * @var array */ @@ -295,72 +280,6 @@ public function getLoginAfterRegistration() return $this->loginAfterRegistration; } - /** - * get user state usage for registration/login process - * - * @return int - */ - public function getEnableUserState() - { - return $this->enableUserState; - } - - /** - * set user state usage for registration/login process - * - * @param boolean $flag - * @return ModuleOptions - */ - public function setEnableUserState($flag) - { - $this->enableUserState = $flag; - return $this; - } - - /** - * get default user state on registration - * - * @return int - */ - public function getDefaultUserState() - { - return $this->defaultUserState; - } - - /** - * set default user state on registration - * - * @param int $state - * @return ModuleOptions - */ - public function setDefaultUserState($state) - { - $this->defaultUserState = $state; - return $this; - } - - /** - * get list of states to allow user login - * - * @return array - */ - public function getAllowedLoginStates() - { - return $this->allowedLoginStates; - } - - /** - * set list of states to allow user login - * - * @param Array $states - * @return ModuleOptions - */ - public function setAllowedLoginStates(Array $states) - { - $this->allowedLoginStates = $states; - return $this; - } - /** * set auth adapters * diff --git a/tests/ZfcUserTest/Authentication/Adapter/DbTest.php b/tests/ZfcUserTest/Authentication/Adapter/DbTest.php index 5d8b3e69..f7e83493 100644 --- a/tests/ZfcUserTest/Authentication/Adapter/DbTest.php +++ b/tests/ZfcUserTest/Authentication/Adapter/DbTest.php @@ -175,40 +175,6 @@ public function testAuthenticateNoUserObject() $this->assertFalse($this->db->isSatisfied()); } - /** - * @covers ZfcUser\Authentication\Adapter\Db::Authenticate - */ - public function testAuthenticationUserStateEnabledUserButUserStateNotInArray() - { - $this->setAuthenticationCredentials(); - $this->setAuthenticationUser(); - - $this->options->expects($this->once()) - ->method('getEnableUserState') - ->will($this->returnValue(true)); - $this->options->expects($this->once()) - ->method('getAllowedLoginStates') - ->will($this->returnValue(array(2, 3))); - - $this->authEvent->expects($this->once()) - ->method('setCode') - ->with(\Zend\Authentication\Result::FAILURE_UNCATEGORIZED) - ->will($this->returnValue($this->authEvent)); - $this->authEvent->expects($this->once()) - ->method('setMessages') - ->with(array('A record with the supplied identity is not active.')) - ->will($this->returnValue($this->authEvent)); - - $this->user->expects($this->once()) - ->method('getState') - ->will($this->returnValue(1)); - - $result = $this->db->authenticate($this->authEvent); - - $this->assertFalse($result); - $this->assertFalse($this->db->isSatisfied()); - } - /** * @covers ZfcUser\Authentication\Adapter\Db::Authenticate */ @@ -217,10 +183,6 @@ public function testAuthenticateWithWrongPassword() $this->setAuthenticationCredentials(); $this->setAuthenticationUser(); - $this->options->expects($this->once()) - ->method('getEnableUserState') - ->will($this->returnValue(false)); - $this->bcrypt->expects($this->once()) ->method('verify') ->will($this->returnValue(false)); @@ -247,10 +209,6 @@ public function testAuthenticationAuthenticatesWithEmail() $this->setAuthenticationCredentials('zfc-user@zf-commons.io'); $this->setAuthenticationEmail(); - $this->options->expects($this->once()) - ->method('getEnableUserState') - ->will($this->returnValue(false)); - $this->bcrypt->expects($this->once()) ->method('verify') ->will($this->returnValue(true)); @@ -293,14 +251,6 @@ public function testAuthenticationAuthenticates() $this->setAuthenticationCredentials(); $this->setAuthenticationUser(); - $this->options->expects($this->once()) - ->method('getEnableUserState') - ->will($this->returnValue(true)); - - $this->options->expects($this->once()) - ->method('getAllowedLoginStates') - ->will($this->returnValue(array(1, 2, 3))); - $this->bcrypt->expects($this->once()) ->method('verify') ->will($this->returnValue(true)); @@ -314,9 +264,6 @@ public function testAuthenticationAuthenticates() $this->user->expects($this->once()) ->method('getId') ->will($this->returnValue(1)); - $this->user->expects($this->once()) - ->method('getState') - ->will($this->returnValue(1)); $this->storage->expects($this->any()) ->method('getNameSpace') diff --git a/tests/ZfcUserTest/Entity/UserTest.php b/tests/ZfcUserTest/Entity/UserTest.php index d9a245b3..f5bceb39 100644 --- a/tests/ZfcUserTest/Entity/UserTest.php +++ b/tests/ZfcUserTest/Entity/UserTest.php @@ -63,14 +63,4 @@ public function testSetGetPassword() $this->user->setPassword('zfcUser'); $this->assertEquals('zfcUser', $this->user->getPassword()); } - - /** - * @covers ZfcUser\Entity\User::setState - * @covers ZfcUser\Entity\User::getState - */ - public function testSetGetState() - { - $this->user->setState(1); - $this->assertEquals(1, $this->user->getState()); - } } diff --git a/tests/ZfcUserTest/Mapper/UserHydratorTest.php b/tests/ZfcUserTest/Mapper/UserHydratorTest.php index 2b0b7af3..ae9529ea 100644 --- a/tests/ZfcUserTest/Mapper/UserHydratorTest.php +++ b/tests/ZfcUserTest/Mapper/UserHydratorTest.php @@ -73,7 +73,6 @@ public function testHydrateWithValidUserObject() 'email' => 'Zfc User', 'display_name' => 'ZfcUser', 'password' => 'c4zyP455w0rd!', - 'state' => '1', 'user_id' => 1 ); @@ -83,7 +82,6 @@ public function testHydrateWithValidUserObject() $this->assertEquals($expectArray['email'], $result->getEmail()); $this->assertEquals($expectArray['display_name'], $result->getDisplayName()); $this->assertEquals(static::ENCRYPTED_PASSWORD, $result->getPassword()); - $this->assertEquals((int) $expectArray['state'], $result->getState()); $this->assertEquals($expectArray['user_id'], $result->getId()); } @@ -97,7 +95,6 @@ public function provideValidUserObjects() 'email' => 'Zfc User', 'display_name' => 'ZfcUser', 'password' => 'ZfcUserPassword', - 'state' => 1, 'user_id' => 1 ); @@ -110,8 +107,7 @@ public function provideValidUserObjects() 'username' => 'zfcuser', 'email' => 'Zfc User', 'display_name' => 'ZfcUser', - 'password' => 'ZfcUserPassword', - 'state' => 1 + 'password' => 'ZfcUserPassword' ); $return[]=array($this->buildUser($buffer), $buffer); diff --git a/tests/ZfcUserTest/Mapper/UserTest.php b/tests/ZfcUserTest/Mapper/UserTest.php index 1fe001a2..c8ba3c03 100644 --- a/tests/ZfcUserTest/Mapper/UserTest.php +++ b/tests/ZfcUserTest/Mapper/UserTest.php @@ -323,7 +323,6 @@ public function providerTestFindBy() $user->setUsername('zfc-user'); $user->setDisplayName('Zfc-User'); $user->setId('1'); - $user->setState(1); $user->setPassword(static::ENCRYPTED_PASSWORD); return array( diff --git a/tests/ZfcUserTest/Mapper/_files/user.sql b/tests/ZfcUserTest/Mapper/_files/user.sql index 2b039ffd..5acfebae 100644 --- a/tests/ZfcUserTest/Mapper/_files/user.sql +++ b/tests/ZfcUserTest/Mapper/_files/user.sql @@ -1,9 +1,9 @@ -INSERT INTO user (username,email,display_name,password,state) -VALUES ('zfc-user', 'zfc-user@github.com', 'Zfc-User', 'c4zyP455w0rd!',1); +INSERT INTO user (username,email,display_name,password) +VALUES ('zfc-user', 'zfc-user@github.com', 'Zfc-User', 'c4zyP455w0rd!'); -INSERT INTO user (username,email,display_name,password,state) -VALUES ('zfc-user2', 'zfc-user2@github.com', 'Zfc-User2', 'c4zyP455w0rd!',1); +INSERT INTO user (username,email,display_name,password) +VALUES ('zfc-user2', 'zfc-user2@github.com', 'Zfc-User2', 'c4zyP455w0rd!'); -INSERT INTO user (username,email,display_name,password,state) -VALUES ('zfc-user3', 'zfc-user@trash-mail.com', 'Zfc-User3', 'c4zyP455w0rd!',1); +INSERT INTO user (username,email,display_name,password) +VALUES ('zfc-user3', 'zfc-user@trash-mail.com', 'Zfc-User3', 'c4zyP455w0rd!'); diff --git a/tests/ZfcUserTest/Options/ModuleOptionsTest.php b/tests/ZfcUserTest/Options/ModuleOptionsTest.php index 35d4ade6..8ac9fe7b 100644 --- a/tests/ZfcUserTest/Options/ModuleOptionsTest.php +++ b/tests/ZfcUserTest/Options/ModuleOptionsTest.php @@ -161,60 +161,6 @@ public function testGetLoginAfterRegistration() $this->assertTrue($this->options->getLoginAfterRegistration()); } - /** - * @covers ZfcUser\Options\ModuleOptions::getEnableUserState - * @covers ZfcUser\Options\ModuleOptions::setEnableUserState - */ - public function testSetGetEnableUserState() - { - $this->options->setEnableUserState(true); - $this->assertTrue($this->options->getEnableUserState()); - } - - /** - * @covers ZfcUser\Options\ModuleOptions::getEnableUserState - */ - public function testGetEnableUserState() - { - $this->assertFalse($this->options->getEnableUserState()); - } - - /** - * @covers ZfcUser\Options\ModuleOptions::getDefaultUserState - */ - public function testGetDefaultUserState() - { - $this->assertEquals(1, $this->options->getDefaultUserState()); - } - - /** - * @covers ZfcUser\Options\ModuleOptions::getDefaultUserState - * @covers ZfcUser\Options\ModuleOptions::setDefaultUserState - */ - public function testSetGetDefaultUserState() - { - $this->options->setDefaultUserState(3); - $this->assertEquals(3, $this->options->getDefaultUserState()); - } - - /** - * @covers ZfcUser\Options\ModuleOptions::getAllowedLoginStates - */ - public function testGetAllowedLoginStates() - { - $this->assertEquals(array(null, 1), $this->options->getAllowedLoginStates()); - } - - /** - * @covers ZfcUser\Options\ModuleOptions::getAllowedLoginStates - * @covers ZfcUser\Options\ModuleOptions::setAllowedLoginStates - */ - public function testSetGetAllowedLoginStates() - { - $this->options->setAllowedLoginStates(array(2, 5, null)); - $this->assertEquals(array(2, 5, null), $this->options->getAllowedLoginStates()); - } - /** * @covers ZfcUser\Options\ModuleOptions::getAuthAdapters */ diff --git a/tests/ZfcUserTest/Service/UserTest.php b/tests/ZfcUserTest/Service/UserTest.php index 17a51fb7..6336553e 100644 --- a/tests/ZfcUserTest/Service/UserTest.php +++ b/tests/ZfcUserTest/Service/UserTest.php @@ -86,51 +86,6 @@ public function testRegisterWithInvalidForm() $this->assertFalse($result); } - /** - * @covers ZfcUser\Service\User::register - */ - public function testRegisterWithUsernameAndDisplayNameUserStateDisabled() - { - $expectArray = array('username' => 'ZfcUser', 'display_name' => 'Zfc User'); - - $user = $this->getMock('ZfcUser\Entity\User'); - - $this->options->expects($this->once()) - ->method('getUserEntityClass') - ->will($this->returnValue('ZfcUser\Entity\User')); - - $registerForm = $this->getMockBuilder('ZfcUser\Form\Register') - ->disableOriginalConstructor() - ->getMock(); - $registerForm->expects($this->once()) - ->method('setHydrator'); - $registerForm->expects($this->once()) - ->method('bind'); - $registerForm->expects($this->once()) - ->method('setData') - ->with($expectArray); - $registerForm->expects($this->once()) - ->method('getData') - ->will($this->returnValue($user)); - $registerForm->expects($this->once()) - ->method('isValid') - ->will($this->returnValue(true)); - - $this->eventManager->expects($this->exactly(2)) - ->method('trigger'); - - $this->mapper->expects($this->once()) - ->method('insert') - ->with($user) - ->will($this->returnValue($user)); - - $this->service->setRegisterForm($registerForm); - - $result = $this->service->register($expectArray); - - $this->assertSame($user, $result); - } - /** * @covers ZfcUser\Service\User::changePassword */