mirror of
https://github.com/elyby/accounts.git
synced 2024-11-30 02:32:26 +05:30
Добавлено запоминание последнего изменения пароля, удалено поле auth_key, поправлена загрузка фикстур для функциональных тестов
This commit is contained in:
parent
7e2247ccb5
commit
d9a218e075
@ -37,10 +37,12 @@ class AccountsController extends Controller {
|
||||
|
||||
return [
|
||||
'id' => $account->id,
|
||||
'uuid' => $account->uuid,
|
||||
'username' => $account->username,
|
||||
'email' => $account->email,
|
||||
'shouldChangePassword' => $account->password_hash_strategy === Account::PASS_HASH_STRATEGY_OLD_ELY,
|
||||
'isActive' => $account->status === Account::STATUS_ACTIVE,
|
||||
'password_changed_at' => $account->password_changed_at,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,6 @@ class RegistrationForm extends BaseApiForm {
|
||||
$account->username = $this->username;
|
||||
$account->password = $this->password;
|
||||
$account->status = Account::STATUS_REGISTERED;
|
||||
$account->generateAuthKey();
|
||||
if (!$account->save()) {
|
||||
throw new ErrorException('Account not created.');
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ use yii\web\IdentityInterface;
|
||||
* @property string $password_hash
|
||||
* @property integer $password_hash_strategy
|
||||
* @property string $password_reset_token
|
||||
* @property string $auth_key
|
||||
* @property integer $status
|
||||
* @property integer $created_at
|
||||
* @property integer $updated_at
|
||||
* @property integer $password_changed_at
|
||||
*
|
||||
* Геттеры-сеттеры:
|
||||
* @property string $password пароль пользователя (только для записи)
|
||||
@ -117,7 +117,7 @@ class Account extends ActiveRecord implements IdentityInterface {
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getAuthKey() {
|
||||
return $this->auth_key;
|
||||
throw new NotSupportedException('This method used for cookie auth, except we using JWT tokens');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,13 +161,7 @@ class Account extends ActiveRecord implements IdentityInterface {
|
||||
public function setPassword($password) {
|
||||
$this->password_hash_strategy = self::PASS_HASH_STRATEGY_YII2;
|
||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates "remember me" authentication key
|
||||
*/
|
||||
public function generateAuthKey() {
|
||||
$this->auth_key = Yii::$app->security->generateRandomString();
|
||||
$this->password_changed_at = time();
|
||||
}
|
||||
|
||||
/**
|
||||
|
21
console/migrations/m160311_211107_password_change_time.php
Normal file
21
console/migrations/m160311_211107_password_change_time.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use console\db\Migration;
|
||||
|
||||
class m160311_211107_password_change_time extends Migration {
|
||||
|
||||
public function safeUp() {
|
||||
$this->addColumn('{{%accounts}}', 'password_changed_at', $this->integer()->notNull());
|
||||
$this->getDb()->createCommand('
|
||||
UPDATE {{%accounts}}
|
||||
SET password_changed_at = created_at
|
||||
')->execute();
|
||||
$this->dropColumn('{{%accounts}}', 'auth_key');
|
||||
}
|
||||
|
||||
public function safeDown() {
|
||||
$this->dropColumn('{{%accounts}}', 'password_changed_at');
|
||||
$this->addColumn('{{%accounts}}', 'auth_key', $this->string(32)->notNull() . ' AFTER `status`');
|
||||
}
|
||||
|
||||
}
|
@ -89,6 +89,7 @@ class ChangePasswordFormTest extends DbTestCase {
|
||||
expect('form should return true', $model->changePassword())->true();
|
||||
expect('new password should be successfully stored into account', $account->validatePassword('my-new-password'))->true();
|
||||
expect('always use new strategy', $account->password_hash_strategy)->equals(Account::PASS_HASH_STRATEGY_YII2);
|
||||
expect('password change time updated', $account->password_changed_at)->greaterOrEquals(time());
|
||||
});
|
||||
|
||||
/** @var Account $account */
|
||||
@ -102,6 +103,7 @@ class ChangePasswordFormTest extends DbTestCase {
|
||||
expect('form should return true', $model->changePassword())->true();
|
||||
expect('new password should be successfully stored into account', $account->validatePassword('my-new-password'))->true();
|
||||
expect('strategy should be changed to modern', $account->password_hash_strategy)->equals(Account::PASS_HASH_STRATEGY_YII2);
|
||||
expect('password change time updated', $account->password_changed_at)->greaterOrEquals(time());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace tests\codeception\common\_support;
|
||||
|
||||
use Codeception\Module;
|
||||
use Codeception\TestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
use tests\codeception\common\fixtures\EmailActivationFixture;
|
||||
use tests\codeception\common\fixtures\OauthClientFixture;
|
||||
@ -29,11 +30,11 @@ class FixtureHelper extends Module {
|
||||
getFixture as protected;
|
||||
}
|
||||
|
||||
public function _beforeSuite($settings = []) {
|
||||
public function _before(TestCase $test) {
|
||||
$this->loadFixtures();
|
||||
}
|
||||
|
||||
public function _afterSuite() {
|
||||
public function _after(TestCase $test) {
|
||||
$this->unloadFixtures();
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,10 @@ return [
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi', # password_0
|
||||
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
|
||||
'password_reset_token' => null,
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'status' => \common\models\Account::STATUS_ACTIVE,
|
||||
'created_at' => 1451775316,
|
||||
'updated_at' => 1451775316,
|
||||
'password_changed_at' => 1451775316,
|
||||
],
|
||||
'user-with-old-password-type' => [
|
||||
'id' => 2,
|
||||
@ -21,10 +21,10 @@ return [
|
||||
'password_hash' => '133c00c463cbd3e491c28cb653ce4718', # 12345678
|
||||
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_OLD_ELY,
|
||||
'password_reset_token' => null,
|
||||
'auth_key' => 'ltTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'status' => \common\models\Account::STATUS_ACTIVE,
|
||||
'created_at' => 1385225069,
|
||||
'updated_at' => 1385225069,
|
||||
'password_changed_at' => 1385225069,
|
||||
],
|
||||
'not-activated-account' => [
|
||||
'id' => 3,
|
||||
@ -34,9 +34,9 @@ return [
|
||||
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
|
||||
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
|
||||
'password_reset_token' => null,
|
||||
'auth_key' => '3AGc12Q7U8lU9umIyCWk5iCnpdPvZ8Up',
|
||||
'status' => \common\models\Account::STATUS_REGISTERED,
|
||||
'created_at' => 1453146616,
|
||||
'updated_at' => 1453146616,
|
||||
'password_changed_at' => 1453146616,
|
||||
]
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user