mirror of
https://github.com/elyby/accounts.git
synced 2024-11-10 15:32:12 +05:30
31 lines
646 B
PHP
31 lines
646 B
PHP
<?php
|
|
namespace api\models\base;
|
|
|
|
use Yii;
|
|
|
|
class PasswordProtectedForm extends ApiForm {
|
|
|
|
public $password;
|
|
|
|
public function rules() {
|
|
return [
|
|
[['password'], 'required', 'message' => 'error.password_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;
|
|
}
|
|
|
|
}
|