mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Реализована форма разблокировки аккаунта
This commit is contained in:
@ -4,6 +4,7 @@ namespace api\modules\internal\controllers;
|
||||
use api\components\ApiUser\AccessControl;
|
||||
use api\controllers\Controller;
|
||||
use api\modules\internal\models\BanForm;
|
||||
use api\modules\internal\models\PardonForm;
|
||||
use common\models\Account;
|
||||
use common\models\OauthScope as S;
|
||||
use Yii;
|
||||
@ -30,8 +31,22 @@ class AccountsController extends Controller {
|
||||
]);
|
||||
}
|
||||
|
||||
public function verbs() {
|
||||
return [
|
||||
'ban' => ['POST', 'DELETE'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionBan(int $accountId) {
|
||||
$account = $this->findAccount($accountId);
|
||||
if (Yii::$app->request->isPost) {
|
||||
return $this->banAccount($account);
|
||||
} else {
|
||||
return $this->pardonAccount($account);
|
||||
}
|
||||
}
|
||||
|
||||
private function banAccount(Account $account) {
|
||||
$model = new BanForm($account);
|
||||
$model->load(Yii::$app->request->post());
|
||||
if (!$model->ban()) {
|
||||
@ -46,6 +61,21 @@ class AccountsController extends Controller {
|
||||
];
|
||||
}
|
||||
|
||||
private function pardonAccount(Account $account) {
|
||||
$model = new PardonForm($account);
|
||||
$model->load(Yii::$app->request->post());
|
||||
if (!$model->pardon()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'errors' => $model->getFirstErrors(),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
private function findAccount(int $accountId): Account {
|
||||
$account = Account::findOne($accountId);
|
||||
if ($account === null) {
|
||||
|
Reference in New Issue
Block a user