diff --git a/src/controllers/AccountController.php b/src/controllers/AccountController.php index 0dffa76d..c4c44043 100644 --- a/src/controllers/AccountController.php +++ b/src/controllers/AccountController.php @@ -15,118 +15,27 @@ public function actions() { return [ 'create' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Account create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating account'), - 'scenario' => 'create-user', - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create-user']); - }, - ], - ], - 'POST html | POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - }, - 'type' => 'user' - ], - ], - ], + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'Account creating task has been added to queue'), + 'error' => Yii::t('app', 'An error occurred when trying to create account') ], 'create-ftponly' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Account create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating account'), - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create-ftponly']); - } - ], - ], - 'POST html | POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - } - ], - ], - ], + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'Account creating task has been added to queue'), + 'error' => Yii::t('app', 'An error occurred when trying to create account') ], 'set-password' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Password changing task has been successfully added to queue'), - 'error' => Yii::t('app', 'An error occurred when trying to change password'), - 'POST html' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ] - ], - 'POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - }, - ] - ], + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => Yii::t('app', 'Password changed'), + 'error' => Yii::t('app', 'Failed to change password'), ], 'set-allowed-ips' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Allowed IPs changing task has been successfully added to queue'), - 'error' => Yii::t('app', 'An error occurred when trying to change allowed IPs'), - 'POST html' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ] - ], - 'POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - }, - ] - ], + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => Yii::t('app', 'Allowed IPs changing task has been successfully added to queue'), + 'error' => Yii::t('app', 'An error occurred when trying to change allowed IPs'), + ], + 'validate-form' => [ + 'class' => 'hipanel\actions\ValidateFormAction', ], ]; } diff --git a/src/controllers/DbController.php b/src/controllers/DbController.php index 84c7cba4..b73679e7 100644 --- a/src/controllers/DbController.php +++ b/src/controllers/DbController.php @@ -8,110 +8,37 @@ namespace hipanel\modules\hosting\controllers; use hipanel\base\CrudController; -use yii\filters\VerbFilter; use Yii; class DbController extends CrudController { - public function behaviors() - { - return [ - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'create' => ['get', 'post'] - ] - ] - ]; - } - public function actions() { return [ - 'delete' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'DB delete task has been created successfully'), - 'error' => Yii::t('app', 'Error while deleting DB'), - 'POST' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => ['index'], - ], - 'error' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ] - ], - ], - 'create' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'DB create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating DB'), - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create']); - } - ], - ], - 'POST html' => [ - 'save' => true, - 'flash' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - } - ], - ], - ], + 'create' => [ + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'DB create task has been created successfully'), + 'error' => Yii::t('app', 'Error while creating DB'), ], - 'set-password' => [ - 'class' => 'hipanel\actions\SwitchAction', + 'set-password' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => Yii::t('app', 'DB password change task has been created successfully'), 'error' => Yii::t('app', 'Error while DB password changing'), - 'POST' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - }, - ] - ], ], - 'truncate' => [ - 'class' => 'hipanel\actions\SwitchAction', + 'truncate' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => Yii::t('app', 'DB truncate task has been created successfully'), 'error' => Yii::t('app', 'Error while truncating DB'), - 'POST' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - } - ], - ] ], 'set-description' => [ - 'class' => 'hipanel\actions\SmartUpdateAction', - 'success' => Yii::t('app', 'Description set successfully'), + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => Yii::t('app', 'DB description set successfully'), + 'error' => Yii::t('app', 'Failed to set DB description'), + ], + 'delete' => [ + 'class' => 'hipanel\actions\SmartDeleteAction', + 'success' => Yii::t('app', 'DB delete task has been created successfully'), + 'error' => Yii::t('app', 'Error while deleting DB'), ], ]; } diff --git a/src/controllers/HdomainController.php b/src/controllers/HdomainController.php index babd8f0e..1261f1e5 100644 --- a/src/controllers/HdomainController.php +++ b/src/controllers/HdomainController.php @@ -7,7 +7,6 @@ namespace hipanel\modules\hosting\controllers; -use hipanel\helpers\ArrayHelper; use Yii; class HdomainController extends \hipanel\base\CrudController @@ -15,60 +14,26 @@ class HdomainController extends \hipanel\base\CrudController public function actions() { return [ + 'index' => [ + 'class' => 'hipanel\actions\IndexAction', + 'findOptions' => ['with_aliases' => true, 'with_vhosts' => true, 'with_request' => true] + ], + 'view' => [ + 'class' => 'hipanel\actions\ViewAction', + 'findOptions' => [ + 'with_aliases' => true, + 'with_vhosts' => true, + 'with_request' => true + ] + ], 'create' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Account create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating account'), - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create']); - }, - ], - ], - 'POST html | POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - }, - 'type' => 'user' - ], - ], - ], + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'Account create task has been created successfully'), + 'error' => Yii::t('app', 'Error while creating account'), + ], + 'validate-form' => [ + 'class' => 'hipanel\actions\ValidateFormAction', ], ]; } - - /** - * @return string - */ - public function actionIndex() - { - $searchModel = static::searchModel(); - $params = Yii::$app->request->queryParams; - $params[$searchModel->formName()] = ArrayHelper::merge($params[$searchModel->formName()], - ['with_aliases' => true, 'with_vhosts' => true, 'with_request' => true]); - $dataProvider = $searchModel->search($params); - - return $this->render('index', compact('searchModel', 'dataProvider')); - } - - public function actionView ($id) { - $model = $this->findModel(['id' => $id, 'with_aliases' => true, 'with_vhosts' => true, 'with_request' => true]); - - return $this->render('view', compact('model')); - } - } diff --git a/src/models/Account.php b/src/models/Account.php index 9787d4ff..a38890b9 100644 --- a/src/models/Account.php +++ b/src/models/Account.php @@ -41,7 +41,7 @@ public function rules() 'type', ], 'safe', - 'on' => ['create-user', 'create-ftponly'] + 'on' => ['create', 'create-ftponly'] ], [ [ @@ -52,7 +52,7 @@ public function rules() 'type', ], 'required', - 'on' => ['create-user', 'create-ftponly'] + 'on' => ['create', 'create-ftponly'] ], [ ['password'], @@ -65,32 +65,32 @@ public function rules() 'compareAttribute' => 'login', 'message' => Yii::t('app', 'Password must not be equal to login'), 'operator' => '!=', - 'on' => ['create-user', 'create-ftponly', 'update', 'set-password'], + 'on' => ['create', 'create-ftponly', 'update', 'set-password'], ], [ 'login', LoginValidator::className(), - 'on' => ['create-user', 'create-ftponly', 'set-password'] + 'on' => ['create', 'create-ftponly', 'set-password'] ], [ 'login', 'in', 'range' => ['root', 'toor'], 'not' => true, - 'on' => ['create-user', 'create-ftponly'], + 'on' => ['create', 'create-ftponly'], 'message' => Yii::t('app', 'You can not use this login') ], [ 'sshftp_ips', 'filter', 'filter' => function ($value) { return ArrayHelper::csplit($value); }, - 'on' => ['create-user', 'create-ftponly', 'update', 'set-allowed-ips'] + 'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips'] ], [ 'sshftp_ips', 'each', 'rule' => [IpValidator::className(), 'negationChar' => true, 'subnet' => null], - 'on' => ['create-user', 'create-ftponly', 'update', 'set-allowed-ips'] + 'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips'] ] ]; } @@ -142,14 +142,13 @@ public function scenarioCommands() { return [ 'set-allowed-ips' => [null, 'SetAllowedIPs'], - 'create-user' => 'create', 'create-ftponly' => 'create', ]; } public function onBeforeValidate() { - if ($this->scenario == 'create-user') { + if ($this->scenario == 'create') { $this->type = 'user'; } elseif ($this->scenario == 'create-ftponly') { $this->type = 'ftponly'; diff --git a/src/views/account/_form.php b/src/views/account/_form.php index 58ab808e..8fd119a0 100644 --- a/src/views/account/_form.php +++ b/src/views/account/_form.php @@ -6,68 +6,63 @@ use hipanel\base\View; use hipanel\modules\client\widgets\combo\ClientCombo; -use hipanel\modules\hosting\widgets\combo\AccountCombo; -use hipanel\modules\hosting\widgets\combo\DbServiceCombo; use hipanel\modules\server\widgets\combo\ServerCombo; use hipanel\widgets\PasswordInput; use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\helpers\Url; - - -$type2action = [ - 'user' => 'create', - 'ftponly' => 'create-ftp' -]; ?> -