mirror of
https://github.com/elyby/accounts.git
synced 2024-12-23 22:00:06 +05:30
49 lines
954 B
PHP
49 lines
954 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace api\validators;
|
|
|
|
use api\rbac\Permissions as P;
|
|
use common\helpers\Error as E;
|
|
use common\models\Account;
|
|
use yii\di\Instance;
|
|
use yii\validators\Validator;
|
|
use yii\web\User;
|
|
|
|
class PasswordRequiredValidator extends Validator {
|
|
|
|
public Account $account;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public $skipOnEmpty = false;
|
|
|
|
/**
|
|
* @var User|string
|
|
*/
|
|
public $user = 'user';
|
|
|
|
public function init() {
|
|
parent::init();
|
|
$this->user = Instance::ensure($this->user, User::class);
|
|
}
|
|
|
|
protected function validateValue($value) {
|
|
if ($this->user->can(P::ESCAPE_IDENTITY_VERIFICATION)) {
|
|
return null;
|
|
}
|
|
|
|
if (empty($value)) {
|
|
return [E::PASSWORD_REQUIRED, []];
|
|
}
|
|
|
|
if ($this->account->validatePassword($value) === false) {
|
|
return [E::PASSWORD_INCORRECT, []];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
}
|