mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлен обработчик для события блокировки аккаунта
This commit is contained in:
@@ -3,10 +3,13 @@ namespace console\controllers;
|
||||
|
||||
use common\components\Mojang\Api as MojangApi;
|
||||
use common\components\Mojang\exceptions\NoContentException;
|
||||
use common\models\Account;
|
||||
use common\models\amqp\AccountBanned;
|
||||
use common\models\amqp\UsernameChanged;
|
||||
use common\models\MojangUsername;
|
||||
use Ely\Amqp\Builder\Configurator;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Yii;
|
||||
|
||||
class AccountQueueController extends AmqpController {
|
||||
|
||||
@@ -17,16 +20,18 @@ class AccountQueueController extends AmqpController {
|
||||
public function configure(Configurator $configurator) {
|
||||
$configurator->exchange->topic()->durable();
|
||||
$configurator->queue->name('accounts-accounts-events')->durable();
|
||||
$configurator->bind->routingKey('accounts.username-changed');
|
||||
$configurator->bind->routingKey('accounts.username-changed')
|
||||
->add()->routingKey('account.account-banned');
|
||||
}
|
||||
|
||||
public function getRoutesMap() {
|
||||
return [
|
||||
'accounts.username-changed' => 'routeUsernameChanged',
|
||||
'accounts.account-banned' => 'routeAccountBanned',
|
||||
];
|
||||
}
|
||||
|
||||
public function routeUsernameChanged(UsernameChanged $body) {
|
||||
public function routeUsernameChanged(UsernameChanged $body): bool {
|
||||
$mojangApi = $this->createMojangApi();
|
||||
try {
|
||||
$response = $mojangApi->usernameToUUID($body->newUsername);
|
||||
@@ -58,10 +63,32 @@ class AccountQueueController extends AmqpController {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function routeAccountBanned(AccountBanned $body): bool {
|
||||
$account = Account::findOne($body->accountId);
|
||||
if ($account === null) {
|
||||
Yii::warning('Cannot find banned account ' . $body->accountId . '. Skipping.');
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($account->sessions as $authSession) {
|
||||
$authSession->delete();
|
||||
}
|
||||
|
||||
foreach ($account->minecraftAccessKeys as $key) {
|
||||
$key->delete();
|
||||
}
|
||||
|
||||
foreach ($account->oauthSessions as $oauthSession) {
|
||||
$oauthSession->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MojangApi
|
||||
*/
|
||||
protected function createMojangApi() : MojangApi {
|
||||
protected function createMojangApi(): MojangApi {
|
||||
return new MojangApi();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user