mirror of
https://github.com/elyby/accounts.git
synced 2024-11-15 09:48:42 +05:30
31 lines
652 B
PHP
31 lines
652 B
PHP
|
<?php
|
||
|
namespace api\models;
|
||
|
|
||
|
use Yii;
|
||
|
|
||
|
class BasePasswordProtectedForm extends BaseApiForm {
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
}
|