From 4583f147ffa3f2f6ee2f3153ce5d8c3d583d5f1c Mon Sep 17 00:00:00 2001 From: Lorenzo Milesi Date: Tue, 6 Feb 2018 19:04:27 +0100 Subject: [PATCH] Renamed field to `password_changed_at` and type INT #102 --- .../m000000_000007_enable_password_expiration.php | 4 ++-- src/User/Model/User.php | 10 +++++----- tests/_data/schema.sql | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/User/Migration/m000000_000007_enable_password_expiration.php b/src/User/Migration/m000000_000007_enable_password_expiration.php index dcee448..f5d70e0 100644 --- a/src/User/Migration/m000000_000007_enable_password_expiration.php +++ b/src/User/Migration/m000000_000007_enable_password_expiration.php @@ -17,11 +17,11 @@ class m000000_000007_enable_password_expiration extends Migration { public function safeUp() { - $this->addColumn('{{%user}}', 'last_password_change', $this->timestamp()->null()); + $this->addColumn('{{%user}}', 'password_changed_at', $this->int()->null()); } public function safeDown() { - $this->dropColumn('{{%user}}', 'last_password_change'); + $this->dropColumn('{{%user}}', 'password_changed_at'); } } diff --git a/src/User/Model/User.php b/src/User/Model/User.php index b765171..4aacbea 100644 --- a/src/User/Model/User.php +++ b/src/User/Model/User.php @@ -50,7 +50,7 @@ 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_changed_at * @property int $password_age * * Defined relations: @@ -98,7 +98,7 @@ class User extends ActiveRecord implements IdentityInterface 'password_hash', $security->generatePasswordHash($this->password, $this->getModule()->blowfishCost) ); - $this->last_password_change = new Expression("NOW()"); + $this->password_changed_at = time(); } return parent::beforeSave($insert); @@ -151,7 +151,7 @@ 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_changed_at' => Yii::t('usuario', 'Last password change'), 'password_age' => Yii::t('usuario', 'Password age'), ]; } @@ -341,10 +341,10 @@ class User extends ActiveRecord implements IdentityInterface */ public function getPassword_age() { - if (is_null($this->last_password_change)) { + if (is_null($this->password_changed_at)) { 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"); } } diff --git a/tests/_data/schema.sql b/tests/_data/schema.sql index 0c25fa7..a282a51 100644 --- a/tests/_data/schema.sql +++ b/tests/_data/schema.sql @@ -73,7 +73,7 @@ CREATE TABLE `user` ( `auth_tf_enabled` tinyint(1) DEFAULT '0', `flags` int(11) NOT NULL DEFAULT '0', `last_login_at` int(11) DEFAULT NULL, - `last_password_change` timestamp, + `password_changed_at` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user_unique_email` (`email`),