Skip to content

Commit

Permalink
Implemented FTP account creating
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Sep 1, 2015
1 parent 89363d9 commit 86c2a81
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace hipanel\modules\hosting\controllers;

use hipanel\helpers\ArrayHelper;
use hipanel\models\Ref;
use Yii;

Expand Down Expand Up @@ -55,6 +56,20 @@ public function actions()
'success' => Yii::t('app', 'Account deleting task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to delete account')
],
'get-directories-list' => [
'class' => 'hipanel\actions\SearchAction',
'findOptions' => ['with_directories' => true],
'ajaxResponseFormatter' => function ($action) {
$results = [];

$model = $action->collection->first;
foreach ($model['path'] as $path) {
$results[] = ['id' => $path, 'text' => $path];
}

return $results;
}
]
];
}

Expand Down
11 changes: 5 additions & 6 deletions src/models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public function init()
public function rules()
{
return [
[['id', 'client_id', 'device_id', 'server_id'], 'integer'],
[['id', 'client_id', 'device_id', 'server_id', 'seller_id', 'uid', 'gid'], 'integer'],
[
['login', 'password', 'uid', 'gid', 'shell', 'client', 'path', 'home', 'device', 'server', 'seller', 'seller_id'],
['login', 'password', 'shell', 'client', 'path', 'home', 'device', 'server', 'seller'],
'safe'
],
[['type', 'type_label', 'state', 'state_label'], 'safe'],
[['ip', 'allowed_ips', 'objects_count', 'request_state', 'request_state_label', 'mail_settings'], 'safe'],
[['login', 'server', 'password', 'sshftp_ips', 'type'], 'safe', 'on' => ['create', 'create-ftponly']],
[['login', 'server', 'password', 'type'], 'required', 'on' => ['create', 'create-ftponly']],
[['id'], 'integer', 'on' => ['set-password', 'set-allowed-ips']],
[['account', 'path'], 'required', 'on' => ['create-ftponly']],
[['login'], 'required', 'on' => ['set-password']],
[['password'], 'required', 'on' => ['set-password']],
[['password'],
Expand Down Expand Up @@ -65,9 +65,8 @@ public function rules()
'rule' => [IpValidator::className(), 'negationChar' => true, 'subnet' => null],
'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips']
],
[
['id'], 'integer', 'on' => ['delete'],
]
[['id'], 'required', 'on' => ['set-password', 'set-allowed-ips', 'delete']],
[['account', 'server'], 'required', 'on' => ['get-directories-list']],
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/models/AccountSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public function searchAttributes()
{
return ArrayHelper::merge($this->defaultSearchAttributes(), [
'with_request',
'with_counters',
'with_directories',
'with_mail_settings',
'with_counters'
]);
}
}
9 changes: 9 additions & 0 deletions src/views/account/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use hipanel\base\View;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\AccountPathCombo;
use hipanel\modules\hosting\widgets\combo\SshAccountCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hipanel\widgets\PasswordInput;
use yii\helpers\Html;
Expand Down Expand Up @@ -38,10 +40,17 @@
<?php
print $form->field($model, "[$i]client")->widget(ClientCombo::className());
print $form->field($model, "[$i]server")->widget(ServerCombo::className());
if ($model->scenario === 'create-ftponly') {
print $form->field($model, "[$i]account")->widget(SshAccountCombo::className());
}

print $form->field($model, "[$i]login");
print $form->field($model, "[$i]password")->widget(PasswordInput::className());

if ($model->scenario === 'create-ftponly') {
print $form->field($model, "[$i]path")->widget(AccountPathCombo::className());
}

print $form->field($model, "[$i]sshftp_ips")->hint(Yii::t('app',
'Access to the account is opened by default. Please input the IPs, for which the access to the server will be granted'))
->input('text', [
Expand Down
13 changes: 13 additions & 0 deletions src/views/account/create-ftponly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/* @var $this yii\web\View */
/* @var $model hipanel\modules\ticket\models\Thread */
/* @var $type string */

$this->title = Yii::t('app', 'Create FTP account');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Accounts'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="account-create">
<?= $this->render('_form', compact('models')) ?>
</div>
5 changes: 3 additions & 2 deletions src/widgets/combo/AccountCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AccountCombo extends Combo
public $name = 'login';

/** @inheritdoc */
public $url = '/hosting/account/search';
public $url = '/hosting/account/index';

/** @inheritdoc */
public $_return = ['id', 'client', 'client_id', 'device', 'device_id'];
Expand All @@ -43,7 +43,8 @@ public function getFilter()
]);
}

public function getPluginOptions($config)
/** @inheritdoc */
public function getPluginOptions($options = [])
{
return parent::getPluginOptions([
'clearWhen' => ['client/client', 'server/server'],
Expand Down
43 changes: 43 additions & 0 deletions src/widgets/combo/AccountPathCombo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace hipanel\modules\hosting\widgets\combo;

use hiqdev\combo\Combo;
use yii\helpers\ArrayHelper;

/**
* Class Account
*/
class AccountPathCombo extends Combo
{
/** @inheritdoc */
public $type = 'hosting/accountPath';

/** @inheritdoc */
public $name = 'path';

/** @inheritdoc */
public $url = '/hosting/account/get-directories-list';

/** @inheritdoc */
public $_return = ['id', 'login', 'server', 'path'];

/** @inheritdoc */
public function getFilter()
{
return ArrayHelper::merge(parent::getFilter(), [
'account' => 'hosting/account',
'server' => 'server/server',
]);
}

/** @inheritdoc */
public function getPluginOptions($options = [])
{
return parent::getPluginOptions([
'clearWhen' => ['hosting/account'],
'activeWhen' => ['hosting/account'],

]);
}
}

0 comments on commit 86c2a81

Please sign in to comment.