mirror of
https://github.com/elyby/accounts.git
synced 2024-12-26 07:09:46 +05:30
951b6928a2
Поправлены именования классов (хз, почему оно прежде работало)
40 lines
948 B
PHP
40 lines
948 B
PHP
<?php
|
|
namespace api\models;
|
|
|
|
use api\models\base\PasswordProtectedForm;
|
|
use common\models\Account;
|
|
use Yii;
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
class ChangeUsernameForm extends PasswordProtectedForm {
|
|
|
|
public $username;
|
|
|
|
public function rules() {
|
|
return ArrayHelper::merge(parent::rules(), [
|
|
[['username'], 'required', 'message' => 'error.{attribute}_required'],
|
|
[['username'], 'validateUsername'],
|
|
]);
|
|
}
|
|
|
|
public function validateUsername($attribute) {
|
|
$account = new Account();
|
|
$account->username = $this->$attribute;
|
|
if (!$account->validate(['username'])) {
|
|
$account->addErrors($account->getErrors('username'));
|
|
}
|
|
}
|
|
|
|
public function change() {
|
|
if (!$this->validate()) {
|
|
return false;
|
|
}
|
|
|
|
$account = $this->getAccount();
|
|
$account->username = $this->username;
|
|
|
|
return $account->save();
|
|
}
|
|
|
|
}
|