mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Базовые модели перенесены в отдельное простраинство имён
Поправлены именования классов (хз, почему оно прежде работало)
This commit is contained in:
39
api/models/base/KeyConfirmationForm.php
Normal file
39
api/models/base/KeyConfirmationForm.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace api\models\base;
|
||||
|
||||
use common\models\EmailActivation;
|
||||
|
||||
class KeyConfirmationForm extends ApiForm {
|
||||
|
||||
public $key;
|
||||
|
||||
private $model;
|
||||
|
||||
public function rules() {
|
||||
return [
|
||||
// TODO: нужно провалидировать количество попыток ввода кода для определённого IP адреса и в случае чего запросить капчу
|
||||
['key', 'required', 'message' => 'error.key_is_required'],
|
||||
['key', 'validateKey'],
|
||||
];
|
||||
}
|
||||
|
||||
public function validateKey($attribute) {
|
||||
if (!$this->hasErrors()) {
|
||||
if ($this->getActivationCodeModel() === null) {
|
||||
$this->addError($attribute, "error.{$attribute}_not_exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmailActivation|null
|
||||
*/
|
||||
public function getActivationCodeModel() {
|
||||
if ($this->model === null) {
|
||||
$this->model = EmailActivation::findOne($this->key);
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user