2016-03-20 04:55:26 +05:30
|
|
|
<?php
|
2016-03-20 05:03:49 +05:30
|
|
|
namespace api\models\base;
|
2016-03-20 04:55:26 +05:30
|
|
|
|
|
|
|
use Yii;
|
|
|
|
|
2016-03-20 05:03:49 +05:30
|
|
|
class PasswordProtectedForm extends ApiForm {
|
2016-03-20 04:55:26 +05:30
|
|
|
|
|
|
|
public $password;
|
|
|
|
|
|
|
|
public function rules() {
|
|
|
|
return [
|
2016-05-23 00:06:02 +05:30
|
|
|
[['password'], 'required', 'message' => 'error.password_required'],
|
2016-03-20 04:55:26 +05:30
|
|
|
[['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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|