2016-08-04 03:37:21 +05:30
|
|
|
<?php
|
|
|
|
namespace api\controllers;
|
|
|
|
|
2016-08-06 19:06:24 +05:30
|
|
|
use api\components\ApiUser\AccessControl;
|
|
|
|
use common\models\OauthScope as S;
|
2016-08-04 03:37:21 +05:30
|
|
|
use Yii;
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
|
|
|
class IdentityInfoController extends ApiController {
|
|
|
|
|
|
|
|
public function behaviors() {
|
|
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::class,
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'actions' => ['index'],
|
|
|
|
'allow' => true,
|
2016-08-06 19:06:24 +05:30
|
|
|
'roles' => [S::ACCOUNT_INFO],
|
2016-08-04 03:37:21 +05:30
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionIndex() {
|
|
|
|
$account = Yii::$app->apiUser->getIdentity()->getAccount();
|
|
|
|
$response = [
|
|
|
|
'id' => $account->id,
|
|
|
|
'uuid' => $account->uuid,
|
2016-08-06 19:06:24 +05:30
|
|
|
'username' => $account->username,
|
2016-08-04 03:37:21 +05:30
|
|
|
'registeredAt' => $account->created_at,
|
|
|
|
'profileLink' => $account->getProfileLink(),
|
|
|
|
'preferredLanguage' => $account->lang,
|
|
|
|
];
|
|
|
|
|
2016-08-06 19:06:24 +05:30
|
|
|
if (Yii::$app->apiUser->can(S::ACCOUNT_EMAIL)) {
|
2016-08-04 03:37:21 +05:30
|
|
|
$response['email'] = $account->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|