Базовые модели перенесены в отдельное простраинство имён

Поправлены именования классов (хз, почему оно прежде работало)
This commit is contained in:
ErickSkrauch
2016-03-20 02:33:49 +03:00
parent e67257b8aa
commit 951b6928a2
12 changed files with 33 additions and 26 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace api\models\base;
use yii\base\Model;
class ApiForm extends Model {
public function formName() {
return '';
}
}

View 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;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace api\models\base;
use Yii;
class PasswordProtectedForm extends ApiForm {
public $password;
public function rules() {
return [
[['password'], 'required', 'message' => 'error.{attribute}_required'],
[['password'], 'validatePassword'],
];
}
public function validatePassword() {
if (!$this->getAccount()->validatePassword($this->password)) {
$this->addError('password', 'error.password_invalid');
}
}
/**
* @return \common\models\Account
*/
protected function getAccount() {
return Yii::$app->user->identity;
}
}