diff --git a/api/controllers/UsersController.php b/api/controllers/UsersController.php new file mode 100644 index 0000000..473b61d --- /dev/null +++ b/api/controllers/UsersController.php @@ -0,0 +1,44 @@ + [ + 'class' => AccessControl::class, + 'rules' => [ + [ + 'actions' => ['current'], + 'allow' => true, + 'roles' => ['@'], + ], + ], + ], + ]); + } + + public function verbs() { + return [ + 'current' => ['GET'], + ]; + } + + public function actionCurrent() { + /** @var Account $account */ + $account = Yii::$app->user->identity; + + return [ + 'id' => $account->id, + 'username' => $account->username, + 'email' => $account->email, + 'shouldChangePassword' => $account->password_hash_strategy === Account::PASS_HASH_STRATEGY_OLD_ELY, + ]; + } + +} diff --git a/tests/codeception/api/_pages/UsersRoute.php b/tests/codeception/api/_pages/UsersRoute.php new file mode 100644 index 0000000..8780f53 --- /dev/null +++ b/tests/codeception/api/_pages/UsersRoute.php @@ -0,0 +1,16 @@ +route = ['users/current']; + $this->actor->sendGET($this->getUrl()); + } + +} diff --git a/tests/codeception/api/functional/UsersCest.php b/tests/codeception/api/functional/UsersCest.php new file mode 100644 index 0000000..ebebd9a --- /dev/null +++ b/tests/codeception/api/functional/UsersCest.php @@ -0,0 +1,36 @@ +route = new UsersRoute($I); + } + + public function testCurrent(FunctionalTester $I, Scenario $scenario) { + $I = new AccountSteps($scenario); + $I->loggedInAsActiveAccount(); + + $this->route->current(); + $I->canSeeResponseCodeIs(200); + $I->canSeeResponseIsJson(); + $I->canSeeResponseContainsJson([ + 'id' => 1, + 'username' => 'Admin', + 'email' => 'admin@ely.by', + 'shouldChangePassword' => false, + ]); + } + +}