mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Реализован функционал получения информации об аккауте после выполнения oAuth авторизации
This commit is contained in:
8
api/components/ApiUser/AccessControl.php
Normal file
8
api/components/ApiUser/AccessControl.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace api\components\ApiUser;
|
||||
|
||||
class AccessControl extends \yii\filters\AccessControl {
|
||||
|
||||
public $user = 'apiUser';
|
||||
|
||||
}
|
||||
@@ -10,10 +10,14 @@ use yii\web\User as YiiUserComponent;
|
||||
*/
|
||||
class Component extends YiiUserComponent {
|
||||
|
||||
public $identity = Identity::class;
|
||||
public $identityClass = Identity::class;
|
||||
|
||||
public $enableSession = false;
|
||||
|
||||
public $loginUrl = null;
|
||||
|
||||
public function getAccessChecker() {
|
||||
return new AuthChecker();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,4 +5,6 @@ return [
|
||||
'/accounts/change-email/confirm-new-email' => 'accounts/change-email-confirm-new-email',
|
||||
|
||||
'/oauth2/v1/<action>' => 'oauth/<action>',
|
||||
|
||||
'/account/v1/info' => 'identity-info/index',
|
||||
];
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use common\models\OauthScope;
|
||||
use api\components\ApiUser\AccessControl;
|
||||
use common\models\OauthScope as S;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class IdentityInfoController extends ApiController {
|
||||
@@ -16,7 +16,7 @@ class IdentityInfoController extends ApiController {
|
||||
[
|
||||
'actions' => ['index'],
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
'roles' => [S::ACCOUNT_INFO],
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -28,12 +28,13 @@ class IdentityInfoController extends ApiController {
|
||||
$response = [
|
||||
'id' => $account->id,
|
||||
'uuid' => $account->uuid,
|
||||
'username' => $account->username,
|
||||
'registeredAt' => $account->created_at,
|
||||
'profileLink' => $account->getProfileLink(),
|
||||
'preferredLanguage' => $account->lang,
|
||||
];
|
||||
|
||||
if (Yii::$app->apiUser->can(OauthScope::ACCOUNT_EMAIL)) {
|
||||
if (Yii::$app->apiUser->can(S::ACCOUNT_EMAIL)) {
|
||||
$response['email'] = $account->email;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user