Упразднён контроллер PasswordProtectedController и заменён на валидатор PasswordRequiredValidator

Реорганизованы тесты для ChangeUsernameFormTest
This commit is contained in:
ErickSkrauch
2016-07-25 14:07:14 +03:00
parent a4dad11be5
commit 31679b84cb
9 changed files with 121 additions and 105 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace api\validators;
use common\helpers\Error as E;
use common\models\Account;
use Yii;
use yii\base\InvalidConfigException;
use yii\validators\Validator;
class PasswordRequiredValidator extends Validator {
/**
* @var Account
*/
public $account;
/**
* @inheritdoc
*/
public $skipOnEmpty = false;
public function init() {
parent::init();
if ($this->account === null) {
$this->account = Yii::$app->user->identity;
}
if (!$this->account instanceof Account) {
throw new InvalidConfigException('account should be instance of ' . Account::class);
}
}
protected function validateValue($value) {
if (empty($value)) {
return [E::PASSWORD_REQUIRED, []];
}
if ($this->account->validatePassword($value) === false) {
return [E::PASSWORD_INVALID, []];
}
return null;
}
}