mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Реализован контроллер для формы запроса на блокировку аккаунта
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user