From 1e7039c05c2df7cebe33772741ed2b11594bbe9f Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 16 Dec 2016 11:36:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=8B=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D1=83=20=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/AccountsController.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/api/modules/internal/controllers/AccountsController.php b/api/modules/internal/controllers/AccountsController.php index 2c86fd3..fd4eb56 100644 --- a/api/modules/internal/controllers/AccountsController.php +++ b/api/modules/internal/controllers/AccountsController.php @@ -3,8 +3,12 @@ namespace api\modules\internal\controllers; use api\components\ApiUser\AccessControl; use api\controllers\Controller; +use api\modules\internal\models\BlockForm; +use common\models\Account; use common\models\OauthScope as S; +use Yii; use yii\helpers\ArrayHelper; +use yii\web\NotFoundHttpException; class AccountsController extends Controller { @@ -24,7 +28,28 @@ class AccountsController extends Controller { } public function actionBlock(int $accountId) { + $account = $this->findAccount($accountId); + $model = new BlockForm($account); + $model->load(Yii::$app->request->post()); + if (!$model->ban()) { + return [ + 'success' => false, + 'errors' => $model->getFirstErrors(), + ]; + } + return [ + 'success' => true, + ]; + } + + private function findAccount(int $accountId): Account { + $account = Account::findOne($accountId); + if ($account === null) { + throw new NotFoundHttpException(); + } + + return $account; } }