mirror of
https://github.com/elyby/accounts.git
synced 2024-11-27 01:02:06 +05:30
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
namespace api\controllers;
|
|
|
|
use common\models\Account;
|
|
use Yii;
|
|
use yii\filters\AccessControl;
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
class AccountsController extends Controller {
|
|
|
|
public function behaviors() {
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
'access' => [
|
|
'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,
|
|
'isActive' => $account->status === Account::STATUS_ACTIVE,
|
|
];
|
|
}
|
|
|
|
}
|