Skip to content

Commit

Permalink
Add "Use existing password" to installer's SMTP settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nchervyakov committed Sep 19, 2014
1 parent 2b9b76a commit e36077f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
26 changes: 23 additions & 3 deletions assets/views/installation/emailsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@
</div>

<div class="form-group">
<?php $useExistingPassword = isset($use_existing_password) && $use_existing_password; ?>
<label>Password:</label>
<input class="form-control<?php $_(isset($password) && $password ? ' js-has-existing' : ''); ?>" type="password" name="password" value="" placeholder="Password" />
<input class="form-control<?php $_(isset($password) && $password ? ' js-has-existing' : ''); ?>"
type="password" name="password" value="" placeholder="Password"
<?php echo $useExistingPassword ? "disabled" : ""; ?>/><br>
<label><input type="checkbox" name="use_existing_password" class="js-use-existing-password"
<?php echo $useExistingPassword ? "checked" : ""; ?> />
Use existing password</label><br>
</div>

<div class="form-group">
Expand Down Expand Up @@ -73,7 +79,11 @@
$(function() {
jQuery(function($) {
var form = $('#emailSettingsForm'),
type = form.find('#mailType');
type = form.find('#mailType'),
$passwordField = $('input[name="password"]'),
$useExistingPw = $('.js-use-existing-password');

form.hzBootstrapValidator();

var updateLayout = function () {
form.find('.type-group').hide();
Expand All @@ -86,11 +96,21 @@
if (form.data('bootstrapValidator')) {
form.data('bootstrapValidator').resetForm();
}
form.hzBootstrapValidator();
$useExistingPw.trigger('change');
};
updateLayout();

type.on('change', updateLayout);

$useExistingPw.on('change', function (ev) {
if ($useExistingPw.is(':checked')) {
$passwordField.attr('disabled', 'disabled');
} else {
$passwordField.removeAttr('disabled');
}
$settingsForm.data('bootstrapValidator').resetForm();
});
$useExistingPw.trigger('change');
});
});
</script>
13 changes: 11 additions & 2 deletions classes/App/Installation/Step/EmailSettingsStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class EmailSettingsStep extends AbstractStep

protected $timeout;

protected $useExistingPassword;

protected $defaultPassword;

protected function processRequest(array $data = [])
{
$this->isValid = false;
Expand All @@ -62,10 +66,11 @@ protected function processRequest(array $data = [])
$this->sendmail_command = $data['sendmail_command'] ?: null;

} else if ($this->type == 'smtp') {
$this->useExistingPassword = (boolean) $data['use_existing_password'];
$this->hostname = $data['hostname'];
$this->port = $data['port'];
$this->username = $data['username'] ?: null;
$this->password = $data['password'] ?: null;
$this->password = $this->useExistingPassword ? $this->defaultPassword : $data['password'];
$this->encryption = $data['encryption'] ?: null;
$this->timeout = $data['timeout'] ?: null;

Expand All @@ -92,7 +97,8 @@ protected function processRequest(array $data = [])

protected function persistFields()
{
return ['type', 'mail_parameters', 'sendmail_command', 'username', 'password', 'hostname', 'port', 'encryption', 'timeout'];
return ['type', 'mail_parameters', 'sendmail_command', 'username', 'password', 'hostname', 'port',
'encryption', 'timeout', 'useExistingPassword', 'defaultPassword'];
}

public function init()
Expand All @@ -109,6 +115,8 @@ public function init()
$this->type = $config['default']['type'];
$this->mail_parameters = $config['default']['mail_parameters'];
$this->sendmail_command = $config['default']['sendmail_command'];

$this->defaultPassword = $this->password;
}

public function getViewData()
Expand All @@ -123,6 +131,7 @@ public function getViewData()
'type' => $this->type,
'mail_parameters' => $this->mail_parameters,
'sendmail_command' => $this->sendmail_command,
'use_existing_password' => $this->useExistingPassword,
];
}

Expand Down

0 comments on commit e36077f

Please sign in to comment.