Merge pull request #136 from maxxer/password_expiration

Password expiration
This commit is contained in:
Antonio Ramirez
2018-02-07 22:51:39 +01:00
committed by GitHub
11 changed files with 194 additions and 2 deletions

View File

@ -22,6 +22,7 @@ use yii\base\InvalidParamException;
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;
@ -49,6 +50,8 @@ use yii\web\IdentityInterface;
* @property int $created_at
* @property int $updated_at
* @property int $last_login_at
* @property int $password_changed_at
* @property int $password_age
*
* Defined relations:
* @property SocialNetworkAccount[] $socialNetworkAccounts
@ -95,6 +98,7 @@ class User extends ActiveRecord implements IdentityInterface
'password_hash',
$security->generatePasswordHash($this->password, $this->getModule()->blowfishCost)
);
$this->password_changed_at = time();
}
return parent::beforeSave($insert);
@ -147,6 +151,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'),
'password_changed_at' => Yii::t('usuario', 'Last password change'),
'password_age' => Yii::t('usuario', 'Password age'),
];
}
@ -328,4 +334,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->password_changed_at)) {
return $this->getModule()->maxPasswordAge;
}
$d = new \DateTime($this->password_changed_at);
return $d->diff(new \DateTime(), true)->format("%a");
}
}