Password expiration feature #102
It's still missing an enforcement which redirects all actions to profile update until the password is changed
This commit is contained in:
@ -19,6 +19,7 @@ use Yii;
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Application;
|
||||
use yii\web\IdentityInterface;
|
||||
@ -46,6 +47,8 @@ use yii\web\IdentityInterface;
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $last_login_at
|
||||
* @property int $last_password_change
|
||||
* @property int $password_age
|
||||
*
|
||||
* Defined relations:
|
||||
* @property SocialNetworkAccount[] $socialNetworkAccounts
|
||||
@ -88,6 +91,7 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
'password_hash',
|
||||
$security->generatePasswordHash($this->password, $this->getModule()->blowfishCost)
|
||||
);
|
||||
$this->last_password_change = new Expression("NOW()");
|
||||
}
|
||||
|
||||
return parent::beforeSave($insert);
|
||||
@ -138,6 +142,8 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
'created_at' => Yii::t('usuario', 'Registration time'),
|
||||
'confirmed_at' => Yii::t('usuario', 'Confirmation time'),
|
||||
'last_login_at' => Yii::t('usuario', 'Last login'),
|
||||
'last_password_change' => Yii::t('usuario', 'Last password change'),
|
||||
'password_age' => Yii::t('usuario', 'Password age'),
|
||||
];
|
||||
}
|
||||
|
||||
@ -312,4 +318,17 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
{
|
||||
throw new NotSupportedException('Method "' . __CLASS__ . '::' . __METHOD__ . '" is not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns password age in days
|
||||
* @return integer
|
||||
*/
|
||||
public function getPassword_age()
|
||||
{
|
||||
if (is_null($this->last_password_change)) {
|
||||
return $this->getModule()->maxPasswordAge;
|
||||
}
|
||||
$d = new \DateTime($this->last_password_change);
|
||||
return $d->diff(new \DateTime(), true)->format("%a");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user