mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Форма смены ника теперь принимает аккаунт через конструктор
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
namespace api\models\profile;
|
||||
|
||||
use api\models\AccountIdentity;
|
||||
use api\models\base\ApiForm;
|
||||
use api\validators\PasswordRequiredValidator;
|
||||
use common\helpers\Amqp;
|
||||
use common\models\Account;
|
||||
use common\models\amqp\UsernameChanged;
|
||||
use common\models\UsernameHistory;
|
||||
use common\validators\UsernameValidator;
|
||||
@@ -19,21 +19,31 @@ class ChangeUsernameForm extends ApiForm {
|
||||
|
||||
public $password;
|
||||
|
||||
public function rules() {
|
||||
/**
|
||||
* @var Account
|
||||
*/
|
||||
private $account;
|
||||
|
||||
public function __construct(Account $account, array $config = []) {
|
||||
parent::__construct($config);
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
public function rules(): array {
|
||||
return [
|
||||
['username', UsernameValidator::class, 'accountCallback' => function() {
|
||||
return $this->getAccount()->id;
|
||||
return $this->account->id;
|
||||
}],
|
||||
['password', PasswordRequiredValidator::class],
|
||||
];
|
||||
}
|
||||
|
||||
public function change() : bool {
|
||||
public function change(): bool {
|
||||
if (!$this->validate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$account = $this->getAccount();
|
||||
$account = $this->account;
|
||||
if ($this->username === $account->username) {
|
||||
return true;
|
||||
}
|
||||
@@ -85,8 +95,4 @@ class ChangeUsernameForm extends ApiForm {
|
||||
Amqp::sendToEventsExchange('accounts.username-changed', $message);
|
||||
}
|
||||
|
||||
protected function getAccount() : AccountIdentity {
|
||||
return Yii::$app->user->identity;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user