Renamed field to password_changed_at and type INT #102

This commit is contained in:
Lorenzo Milesi
2018-02-06 19:04:27 +01:00
parent c004a7c4c1
commit 4583f147ff
3 changed files with 8 additions and 8 deletions

View File

@ -17,11 +17,11 @@ class m000000_000007_enable_password_expiration extends Migration
{ {
public function safeUp() public function safeUp()
{ {
$this->addColumn('{{%user}}', 'last_password_change', $this->timestamp()->null()); $this->addColumn('{{%user}}', 'password_changed_at', $this->int()->null());
} }
public function safeDown() public function safeDown()
{ {
$this->dropColumn('{{%user}}', 'last_password_change'); $this->dropColumn('{{%user}}', 'password_changed_at');
} }
} }

View File

@ -50,7 +50,7 @@ use yii\web\IdentityInterface;
* @property int $created_at * @property int $created_at
* @property int $updated_at * @property int $updated_at
* @property int $last_login_at * @property int $last_login_at
* @property int $last_password_change * @property int $password_changed_at
* @property int $password_age * @property int $password_age
* *
* Defined relations: * Defined relations:
@ -98,7 +98,7 @@ class User extends ActiveRecord implements IdentityInterface
'password_hash', 'password_hash',
$security->generatePasswordHash($this->password, $this->getModule()->blowfishCost) $security->generatePasswordHash($this->password, $this->getModule()->blowfishCost)
); );
$this->last_password_change = new Expression("NOW()"); $this->password_changed_at = time();
} }
return parent::beforeSave($insert); return parent::beforeSave($insert);
@ -151,7 +151,7 @@ class User extends ActiveRecord implements IdentityInterface
'created_at' => Yii::t('usuario', 'Registration time'), 'created_at' => Yii::t('usuario', 'Registration time'),
'confirmed_at' => Yii::t('usuario', 'Confirmation time'), 'confirmed_at' => Yii::t('usuario', 'Confirmation time'),
'last_login_at' => Yii::t('usuario', 'Last login'), 'last_login_at' => Yii::t('usuario', 'Last login'),
'last_password_change' => Yii::t('usuario', 'Last password change'), 'password_changed_at' => Yii::t('usuario', 'Last password change'),
'password_age' => Yii::t('usuario', 'Password age'), 'password_age' => Yii::t('usuario', 'Password age'),
]; ];
} }
@ -341,10 +341,10 @@ class User extends ActiveRecord implements IdentityInterface
*/ */
public function getPassword_age() public function getPassword_age()
{ {
if (is_null($this->last_password_change)) { if (is_null($this->password_changed_at)) {
return $this->getModule()->maxPasswordAge; return $this->getModule()->maxPasswordAge;
} }
$d = new \DateTime($this->last_password_change); $d = new \DateTime($this->password_changed_at);
return $d->diff(new \DateTime(), true)->format("%a"); return $d->diff(new \DateTime(), true)->format("%a");
} }
} }

View File

@ -73,7 +73,7 @@ CREATE TABLE `user` (
`auth_tf_enabled` tinyint(1) DEFAULT '0', `auth_tf_enabled` tinyint(1) DEFAULT '0',
`flags` int(11) NOT NULL DEFAULT '0', `flags` int(11) NOT NULL DEFAULT '0',
`last_login_at` int(11) DEFAULT NULL, `last_login_at` int(11) DEFAULT NULL,
`last_password_change` timestamp, `password_changed_at` int(11) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `user_unique_email` (`email`), UNIQUE KEY `user_unique_email` (`email`),