mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Логика проверки ключа из KeyConfirmationForm вынесена в отдельный валидатор
У EmailActivationFixture зафиксирован стандартный путь к файлу данных
This commit is contained in:
33
api/validators/EmailActivationKeyValidator.php
Normal file
33
api/validators/EmailActivationKeyValidator.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace api\validators;
|
||||
|
||||
use common\models\EmailActivation;
|
||||
use yii\validators\Validator;
|
||||
|
||||
class EmailActivationKeyValidator extends Validator {
|
||||
|
||||
public $notExist = 'error.key_not_exists';
|
||||
|
||||
public $expired = 'error.key_expire';
|
||||
|
||||
public function validateValue($value) {
|
||||
if (($model = $this->findEmailActivationModel($value)) === null) {
|
||||
return [$this->notExist, []];
|
||||
}
|
||||
|
||||
if ($model->isExpired()) {
|
||||
return [$this->expired, []];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return null|EmailActivation
|
||||
*/
|
||||
protected function findEmailActivationModel($key) {
|
||||
return EmailActivation::findOne($key);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user