Skip to content

Commit

Permalink
Removed expired and credentialsExpired fields from User model (#1956)
Browse files Browse the repository at this point in the history
Removed expired and credentialsExpired fields from User model
  • Loading branch information
XWB committed Nov 15, 2016
1 parent dc8e624 commit 4ea37a5
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 101 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -18,6 +18,7 @@ Changelog
* [BC break] Removed `UserManager::refreshUser`.
* [BC break] Removed `UserManager::loadUserByUsername`.
* [BC break] Removed `UserManager::supportsClass`.
* [BC break] Removed unused properties `expired` and `credentialsExpired` including corresponding methods.
* [BC break] The signature of the `Initializer` constructor has changed.
* [BC break] The signature of the `LoginManager` constructor has changed.
* [BC break] The signature of the `UserListener` constructor has changed.
Expand Down
86 changes: 8 additions & 78 deletions Model/User.php
Expand Up @@ -100,11 +100,6 @@ abstract class User implements UserInterface, GroupableInterface
*/
protected $locked;

/**
* @var bool
*/
protected $expired;

/**
* @var \DateTime
*/
Expand All @@ -115,11 +110,6 @@ abstract class User implements UserInterface, GroupableInterface
*/
protected $roles;

/**
* @var bool
*/
protected $credentialsExpired;

/**
* @var \DateTime
*/
Expand All @@ -133,9 +123,7 @@ public function __construct()
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
$this->enabled = false;
$this->locked = false;
$this->expired = false;
$this->roles = array();
$this->credentialsExpired = false;
}

/**
Expand Down Expand Up @@ -165,9 +153,7 @@ public function serialize()
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id,
$this->expiresAt,
Expand All @@ -183,18 +169,21 @@ public function serialize()
public function unserialize($serialized)
{
$data = unserialize($serialized);
// add a few extra elements in the array to ensure that we have enough keys when unserializing
// older data which does not include all properties.
$data = array_merge($data, array_fill(0, 2, null));

if (9 === count($data)) {
unset($data[4], $data[6]);

// add a few extra elements in the array to ensure that we have enough keys when unserializing
// older data which does not include all properties.
$data = array_merge($data, array_fill(0, 4, null));
}

list(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id,
$this->expiresAt,
Expand Down Expand Up @@ -324,10 +313,6 @@ public function hasRole($role)
*/
public function isAccountNonExpired()
{
if (true === $this->expired) {
return false;
}

if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
return false;
}
Expand All @@ -348,44 +333,18 @@ public function isAccountNonLocked()
*/
public function isCredentialsNonExpired()
{
if (true === $this->credentialsExpired) {
return false;
}

if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
return false;
}

return true;
}

/**
* @return bool
*/
public function isCredentialsExpired()
{
return !$this->isCredentialsNonExpired();
}

/**
* {@inheritdoc}
*/
public function isEnabled()
{
return $this->enabled;
}

/**
* @return bool
*/
public function isExpired()
{
return !$this->isAccountNonExpired();
}

/**
* @return bool
*/
public function isLocked()
{
return !$this->isAccountNonLocked();
Expand Down Expand Up @@ -444,21 +403,6 @@ public function setCredentialsExpireAt(\DateTime $date = null)
return $this;
}

/**
* @param bool $boolean
*
* @return User
*/
public function setCredentialsExpired($boolean)
{
$this->credentialsExpired = $boolean;

return $this;
}

/**
* {@inheritdoc}
*/
public function setEmail($email)
{
$this->email = $email;
Expand Down Expand Up @@ -486,20 +430,6 @@ public function setEnabled($boolean)
return $this;
}

/**
* Sets this user to expired.
*
* @param bool $boolean
*
* @return User
*/
public function setExpired($boolean)
{
$this->expired = (bool) $boolean;

return $this;
}

/**
* @param \DateTime $date
*
Expand Down
12 changes: 0 additions & 12 deletions Propel/User.php
Expand Up @@ -47,9 +47,7 @@ public function serialize()
$this->username,
$this->salt,
$this->password,
$this->expired,
$this->locked,
$this->credentials_expired,
$this->enabled,
$this->_new,
)
Expand All @@ -72,9 +70,7 @@ public function unserialize($serialized)
$this->username,
$this->salt,
$this->password,
$this->expired,
$this->locked,
$this->credentials_expired,
$this->enabled,
$this->_new
) = $data;
Expand Down Expand Up @@ -171,10 +167,6 @@ public function setRoles(array $v)
*/
public function isAccountNonExpired()
{
if (true === $this->getExpired()) {
return false;
}

if (null !== $this->getExpiresAt() && $this->getExpiresAt()->getTimestamp() < time()) {
return false;
}
Expand All @@ -195,10 +187,6 @@ public function isAccountNonLocked()
*/
public function isCredentialsNonExpired()
{
if (true === $this->getCredentialsExpired()) {
return false;
}

if (null !== $this->getCredentialsExpireAt() && $this->getCredentialsExpireAt()->getTimestamp() < time()) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion Resources/config/doctrine-mapping/User.couchdb.xml
Expand Up @@ -12,7 +12,6 @@
<field name="password" fieldName="password" type="string" />
<field name="lastLogin" fieldName="lastLogin" type="datetime" />
<field name="locked" fieldName="locked" type="mixed" />
<field name="expired" fieldName="expired" type="mixed" />
<field name="expiresAt" fieldName="expiresAt" type="datetime" />
<field name="confirmationToken" fieldName="confirmationToken" type="string" />
<field name="passwordRequestedAt" fieldName="passwordRequestedAt" type="datetime" />
Expand Down
4 changes: 0 additions & 4 deletions Resources/config/doctrine-mapping/User.mongodb.xml
Expand Up @@ -24,8 +24,6 @@

<field name="locked" fieldName="locked" type="boolean" />

<field name="expired" fieldName="expired" type="boolean" />

<field name="expiresAt" fieldName="expiresAt" type="date" />

<field name="confirmationToken" fieldName="confirmationToken" type="string" />
Expand All @@ -34,8 +32,6 @@

<field name="roles" fieldName="roles" type="collection" />

<field name="credentialsExpired" fieldName="credentialsExpired" type="boolean" />

<field name="credentialsExpireAt" fieldName="credentialsExpireAt" type="date" />
<indexes>
<index>
Expand Down
4 changes: 0 additions & 4 deletions Resources/config/doctrine-mapping/User.orm.xml
Expand Up @@ -24,8 +24,6 @@

<field name="locked" column="locked" type="boolean" />

<field name="expired" column="expired" type="boolean" />

<field name="expiresAt" column="expires_at" type="datetime" nullable="true" />

<field name="confirmationToken" column="confirmation_token" type="string" length="180" unique="true" nullable="true" />
Expand All @@ -34,8 +32,6 @@

<field name="roles" column="roles" type="array" />

<field name="credentialsExpired" column="credentials_expired" type="boolean" />

<field name="credentialsExpireAt" column="credentials_expire_at" type="datetime" nullable="true" />

</mapped-superclass>
Expand Down
2 changes: 0 additions & 2 deletions Resources/config/propel/schema.xml
Expand Up @@ -20,15 +20,13 @@
<column name="password" type="varchar" size="255" required="true" />
<column name="last_login" type="timestamp" required="false" />
<column name="locked" type="boolean" defaultValue="false" />
<column name="expired" type="boolean" defaultValue="false" />
<column name="expires_at" type="timestamp" required="false" />
<column name="confirmation_token" type="varchar" size="255" required="false" />
<unique>
<unique-column name="confirmation_token" />
</unique>

<column name="password_requested_at" type="timestamp" required="false" />
<column name="credentials_expired" type="boolean" defaultValue="false" />
<column name="credentials_expire_at" type="timestamp" required="false" />
<column name="roles" type="array" />

Expand Down
10 changes: 10 additions & 0 deletions Upgrade.md
Expand Up @@ -6,6 +6,16 @@ break. For the full list of changes, please look at the Changelog file.

## 2.0.0-alpha3 to 2.0.0-alpha4

Methods and properties removed from `FOS\UserBundle\Model\User`

- `$expired`
- `$credentialsExpired`
- `setExpired()` (use `setExpireAt(\DateTime::now()` instead)

This comment has been minimized.

Copy link
@bitgandtter

bitgandtter Nov 15, 2016

the method is setExpiresAt actually

This comment has been minimized.

Copy link
@XWB

XWB Nov 22, 2016

Author Member

Nice catch!

- `setCredentialsExpired()` (use `setCredentialsExpireAt(\DateTime::now()` instead)

You need to drop the fields `expired` and `credentials_expired` from your database
schema, because they aren't mapped anymore.

### LoginManager

The signature of the LoginManager constructor has changed.
Expand Down

0 comments on commit 4ea37a5

Please sign in to comment.