2016-12-11 17:07:55 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\internal\controllers;
|
|
|
|
|
|
|
|
use api\components\ApiUser\AccessControl;
|
|
|
|
use api\controllers\Controller;
|
2016-12-18 04:50:53 +05:30
|
|
|
use api\modules\internal\models\BanForm;
|
2016-12-16 14:06:21 +05:30
|
|
|
use common\models\Account;
|
2016-12-11 17:07:55 +05:30
|
|
|
use common\models\OauthScope as S;
|
2016-12-16 14:06:21 +05:30
|
|
|
use Yii;
|
2016-12-11 17:07:55 +05:30
|
|
|
use yii\helpers\ArrayHelper;
|
2016-12-16 14:06:21 +05:30
|
|
|
use yii\web\NotFoundHttpException;
|
2016-12-11 17:07:55 +05:30
|
|
|
|
|
|
|
class AccountsController extends Controller {
|
|
|
|
|
|
|
|
public function behaviors() {
|
|
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
2016-12-18 04:50:53 +05:30
|
|
|
'authenticator' => [
|
|
|
|
'user' => Yii::$app->apiUser,
|
|
|
|
],
|
2016-12-11 17:07:55 +05:30
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::class,
|
|
|
|
'rules' => [
|
|
|
|
[
|
2016-12-18 04:50:53 +05:30
|
|
|
'actions' => ['ban'],
|
2016-12-11 17:07:55 +05:30
|
|
|
'allow' => true,
|
|
|
|
'roles' => [S::ACCOUNT_BLOCK],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-12-18 04:50:53 +05:30
|
|
|
public function actionBan(int $accountId) {
|
2016-12-16 14:06:21 +05:30
|
|
|
$account = $this->findAccount($accountId);
|
2016-12-18 04:50:53 +05:30
|
|
|
$model = new BanForm($account);
|
2016-12-16 14:06:21 +05:30
|
|
|
$model->load(Yii::$app->request->post());
|
|
|
|
if (!$model->ban()) {
|
|
|
|
return [
|
|
|
|
'success' => false,
|
|
|
|
'errors' => $model->getFirstErrors(),
|
|
|
|
];
|
|
|
|
}
|
2016-12-11 17:07:55 +05:30
|
|
|
|
2016-12-16 14:06:21 +05:30
|
|
|
return [
|
|
|
|
'success' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function findAccount(int $accountId): Account {
|
|
|
|
$account = Account::findOne($accountId);
|
|
|
|
if ($account === null) {
|
|
|
|
throw new NotFoundHttpException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $account;
|
2016-12-11 17:07:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|