From 0198a3e01049471bb172247d218b05862406411d Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 21 Sep 2017 20:00:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2=20=D0=BA=20?= =?UTF-8?q?=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0=D0=BC=20=D0=B2?= =?UTF-8?q?=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/config/routes.php | 12 +++++++++ .../controllers/DefaultController.php | 27 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/api/config/routes.php b/api/config/routes.php index 563913d..aa624a5 100644 --- a/api/config/routes.php +++ b/api/config/routes.php @@ -13,6 +13,18 @@ return [ 'DELETE /v1/accounts//ban' => 'accounts/default/pardon', '/v1/accounts//' => 'accounts/default/', + 'GET /accounts/current' => 'accounts/default/get', + 'POST /accounts/change-username' => 'accounts/default/username', + 'POST /accounts/change-password' => 'accounts/default/password', + 'POST /accounts/change-email/initialize' => 'accounts/default/email-verification', + 'POST /accounts/change-email/submit-new-email' => 'accounts/default/new-email-verification', + 'POST /accounts/change-email/confirm-new-email' => 'accounts/default/email', + 'POST /accounts/accept-rules' => 'accounts/default/rules', + 'GET /two-factor-auth' => 'accounts/default/get-two-factor-auth-credentials', + 'POST /two-factor-auth' => 'accounts/default/enable-two-factor-auth', + 'DELETE /two-factor-auth' => 'accounts/default/disable-two-factor-auth', + 'POST /accounts/change-lang' => 'accounts/default/language', + '/account/v1/info' => 'identity-info/index', '/minecraft/session/join' => 'session/session/join', diff --git a/api/modules/accounts/controllers/DefaultController.php b/api/modules/accounts/controllers/DefaultController.php index fe078cf..cc7bcb9 100644 --- a/api/modules/accounts/controllers/DefaultController.php +++ b/api/modules/accounts/controllers/DefaultController.php @@ -16,12 +16,23 @@ class DefaultController extends Controller { public function behaviors(): array { $paramsCallback = function() { + $id = Yii::$app->request->get('id'); + if ($id === null) { + $identity = Yii::$app->user->getIdentity(); + if ($identity !== null) { + $account = $identity->getAccount(); + if ($account !== null) { + $id = $account->id; + } + } + } + return [ - 'accountId' => Yii::$app->request->get('id'), + 'accountId' => $id, ]; }; - return ArrayHelper::merge(Controller::behaviors(), [ + return ArrayHelper::merge(parent::behaviors(), [ 'access' => [ 'class' => AccessControl::class, 'rules' => [ @@ -121,6 +132,18 @@ class DefaultController extends Controller { return (new TwoFactorAuthInfo($this->findAccount($id)))->getCredentials(); } + public function bindActionParams($action, $params) { + if (!isset($params['id'])) { + /** @noinspection NullPointerExceptionInspection */ + $account = Yii::$app->user->getIdentity()->getAccount(); + if ($account !== null) { + $params['id'] = $account->id; + } + } + + return parent::bindActionParams($action, $params); + } + private function findAccount(int $id): Account { $account = Account::findOne($id); if ($account === null) {