mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Логика проверки ключа из KeyConfirmationForm вынесена в отдельный валидатор
У EmailActivationFixture зафиксирован стандартный путь к файлу данных
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace api\models\base;
|
||||
|
||||
use api\validators\EmailActivationKeyValidator;
|
||||
use common\models\EmailActivation;
|
||||
|
||||
class KeyConfirmationForm extends ApiForm {
|
||||
@@ -13,27 +14,10 @@ class KeyConfirmationForm extends ApiForm {
|
||||
return [
|
||||
// TODO: нужно провалидировать количество попыток ввода кода для определённого IP адреса и в случае чего запросить капчу
|
||||
['key', 'required', 'message' => 'error.key_is_required'],
|
||||
['key', 'validateKey'],
|
||||
['key', 'validateKeyExpiration'],
|
||||
['key', EmailActivationKeyValidator::class],
|
||||
];
|
||||
}
|
||||
|
||||
public function validateKey($attribute) {
|
||||
if (!$this->hasErrors()) {
|
||||
if ($this->getActivationCodeModel() === null) {
|
||||
$this->addError($attribute, "error.{$attribute}_not_exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validateKeyExpiration($attribute) {
|
||||
if (!$this->hasErrors()) {
|
||||
if ($this->getActivationCodeModel()->isExpired()) {
|
||||
$this->addError($attribute, "error.{$attribute}_expire");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmailActivation|null
|
||||
*/
|
||||
|
Reference in New Issue
Block a user