2016-02-24 04:04:01 +05:30
|
|
|
<?php
|
|
|
|
namespace api\controllers;
|
|
|
|
|
|
|
|
use common\models\Account;
|
|
|
|
use Yii;
|
|
|
|
use yii\filters\AccessControl;
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
2016-02-26 04:15:21 +05:30
|
|
|
class AccountsController extends Controller {
|
2016-02-24 04:04:01 +05:30
|
|
|
|
|
|
|
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,
|
2016-02-26 11:55:47 +05:30
|
|
|
'isActive' => $account->status === Account::STATUS_ACTIVE,
|
2016-02-24 04:04:01 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|