mirror of
https://github.com/elyby/accounts.git
synced 2024-11-17 18:53:00 +05:30
Implemented the ability to get information about the current account by 0 id
This commit is contained in:
parent
0cfa64890d
commit
918501da81
@ -15,9 +15,9 @@ use yii\web\NotFoundHttpException;
|
|||||||
class DefaultController extends Controller {
|
class DefaultController extends Controller {
|
||||||
|
|
||||||
public function behaviors(): array {
|
public function behaviors(): array {
|
||||||
$paramsCallback = function() {
|
$paramsCallback = function(): array {
|
||||||
$id = Yii::$app->request->get('id');
|
$id = (int)Yii::$app->request->get('id');
|
||||||
if ($id === null) {
|
if ($id === 0) {
|
||||||
$identity = Yii::$app->user->getIdentity();
|
$identity = Yii::$app->user->getIdentity();
|
||||||
if ($identity !== null) {
|
if ($identity !== null) {
|
||||||
$account = $identity->getAccount();
|
$account = $identity->getAccount();
|
||||||
@ -132,7 +132,7 @@ class DefaultController extends Controller {
|
|||||||
return (new TwoFactorAuthInfo($this->findAccount($id)))->getCredentials();
|
return (new TwoFactorAuthInfo($this->findAccount($id)))->getCredentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bindActionParams($action, $params) {
|
public function bindActionParams($action, $params): array {
|
||||||
if (!isset($params['id'])) {
|
if (!isset($params['id'])) {
|
||||||
/** @noinspection NullPointerExceptionInspection */
|
/** @noinspection NullPointerExceptionInspection */
|
||||||
$account = Yii::$app->user->getIdentity()->getAccount();
|
$account = Yii::$app->user->getIdentity()->getAccount();
|
||||||
@ -145,7 +145,13 @@ class DefaultController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function findAccount(int $id): Account {
|
private function findAccount(int $id): Account {
|
||||||
|
if ($id === 0) {
|
||||||
|
/** @noinspection NullPointerExceptionInspection */
|
||||||
|
$account = Yii::$app->user->getIdentity()->getAccount();
|
||||||
|
} else {
|
||||||
$account = Account::findOne($id);
|
$account = Account::findOne($id);
|
||||||
|
}
|
||||||
|
|
||||||
if ($account === null) {
|
if ($account === null) {
|
||||||
throw new NotFoundHttpException();
|
throw new NotFoundHttpException();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,28 @@ class GetCest {
|
|||||||
$I->canSeeResponseJsonMatchesJsonPath('$.passwordChangedAt');
|
$I->canSeeResponseJsonMatchesJsonPath('$.passwordChangedAt');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetInfoAboutCurrentUser(FunctionalTester $I) {
|
||||||
|
$I->wantTo('get info about user with 0 id, e.g. current');
|
||||||
|
$I->amAuthenticated();
|
||||||
|
|
||||||
|
$this->route->get(0);
|
||||||
|
$I->canSeeResponseCodeIs(200);
|
||||||
|
$I->canSeeResponseIsJson();
|
||||||
|
$I->canSeeResponseContainsJson([
|
||||||
|
'id' => 1,
|
||||||
|
'uuid' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
||||||
|
'username' => 'Admin',
|
||||||
|
'isOtpEnabled' => false,
|
||||||
|
'email' => 'admin@ely.by',
|
||||||
|
'lang' => 'en',
|
||||||
|
'isActive' => true,
|
||||||
|
'hasMojangUsernameCollision' => false,
|
||||||
|
'shouldAcceptRules' => false,
|
||||||
|
'elyProfileLink' => 'http://ely.by/u1',
|
||||||
|
]);
|
||||||
|
$I->canSeeResponseJsonMatchesJsonPath('$.passwordChangedAt');
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetWithNotAcceptedLatestRules(FunctionalTester $I) {
|
public function testGetWithNotAcceptedLatestRules(FunctionalTester $I) {
|
||||||
$accountId = $I->amAuthenticated('Veleyaba');
|
$accountId = $I->amAuthenticated('Veleyaba');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user