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 [
|
|
|
|
[['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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|