Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BC BREAK] Remove state from user entity #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions data/schema.ibmdb2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 1 addition & 2 deletions data/schema.mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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";
1 change: 0 additions & 1 deletion data/schema.pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions data/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 1 addition & 2 deletions data/schema.sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
10 changes: 0 additions & 10 deletions src/ZfcUser/Authentication/Adapter/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions src/ZfcUser/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class User implements UserInterface
*/
protected $password;

/**
* @var int
*/
protected $state;

/**
* Get id.
*
Expand Down Expand Up @@ -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;
}
}
7 changes: 0 additions & 7 deletions src/ZfcUser/Entity/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,4 @@ public function getDisplayName();
* @return string password
*/
public function getPassword();

/**
* Get state.
*
* @return int
*/
public function getState();
}
81 changes: 0 additions & 81 deletions src/ZfcUser/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*
Expand Down
53 changes: 0 additions & 53 deletions tests/ZfcUserTest/Authentication/Adapter/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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));
Expand All @@ -247,10 +209,6 @@ public function testAuthenticationAuthenticatesWithEmail()
$this->setAuthenticationCredentials('[email protected]');
$this->setAuthenticationEmail();

$this->options->expects($this->once())
->method('getEnableUserState')
->will($this->returnValue(false));

$this->bcrypt->expects($this->once())
->method('verify')
->will($this->returnValue(true));
Expand Down Expand Up @@ -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));
Expand All @@ -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')
Expand Down
10 changes: 0 additions & 10 deletions tests/ZfcUserTest/Entity/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
6 changes: 1 addition & 5 deletions tests/ZfcUserTest/Mapper/UserHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function testHydrateWithValidUserObject()
'email' => 'Zfc User',
'display_name' => 'ZfcUser',
'password' => 'c4zyP455w0rd!',
'state' => '1',
'user_id' => 1
);

Expand All @@ -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());
}

Expand All @@ -97,7 +95,6 @@ public function provideValidUserObjects()
'email' => 'Zfc User',
'display_name' => 'ZfcUser',
'password' => 'ZfcUserPassword',
'state' => 1,
'user_id' => 1
);

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/ZfcUserTest/Mapper/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions tests/ZfcUserTest/Mapper/_files/user.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

INSERT INTO user (username,email,display_name,password,state)
VALUES ('zfc-user', '[email protected]', 'Zfc-User', 'c4zyP455w0rd!',1);
INSERT INTO user (username,email,display_name,password)
VALUES ('zfc-user', '[email protected]', 'Zfc-User', 'c4zyP455w0rd!');

INSERT INTO user (username,email,display_name,password,state)
VALUES ('zfc-user2', '[email protected]', 'Zfc-User2', 'c4zyP455w0rd!',1);
INSERT INTO user (username,email,display_name,password)
VALUES ('zfc-user2', '[email protected]', 'Zfc-User2', 'c4zyP455w0rd!');

INSERT INTO user (username,email,display_name,password,state)
VALUES ('zfc-user3', '[email protected]', 'Zfc-User3', 'c4zyP455w0rd!',1);
INSERT INTO user (username,email,display_name,password)
VALUES ('zfc-user3', '[email protected]', 'Zfc-User3', 'c4zyP455w0rd!');
Loading