Skip to content

Commit

Permalink
https://github.com/opencart/opencart/issues/13454
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Jun 16, 2024
1 parent fbc3a48 commit eff344c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
28 changes: 15 additions & 13 deletions upload/install/controller/install/step_3.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ public function save(): void {
}

if (!$this->request->post['db_hostname']) {
$json['db_hostname'] = $this->language->get('error_db_hostname');
$json['error']['db_hostname'] = $this->language->get('error_db_hostname');
}

if (!$this->request->post['db_username']) {
$json['db_username'] = $this->language->get('error_db_username');
$json['error']['db_username'] = $this->language->get('error_db_username');
}

if (!$this->request->post['db_database']) {
$json['db_database'] = $this->language->get('error_db_database');
$json['error']['db_database'] = $this->language->get('error_db_database');
}

if (!$this->request->post['db_port']) {
$json['db_port'] = $this->language->get('error_db_port');
$json['error']['db_port'] = $this->language->get('error_db_port');
}

if ($this->request->post['db_prefix'] && preg_match('/[^a-z0-9_]/', $this->request->post['db_prefix'])) {
$json['db_prefix'] = $this->language->get('error_db_prefix');
$json['error']['db_prefix'] = $this->language->get('error_db_prefix');
}

$db_drivers = [
Expand All @@ -118,33 +118,35 @@ public function save(): void {
];

if (!in_array($this->request->post['db_driver'], $db_drivers)) {
$json['db_driver'] = $this->language->get('error_db_driver');
} else {
$json['error']['db_driver'] = $this->language->get('error_db_driver');
}

if (!$json) {
try {
$db = new \Opencart\System\Library\DB($this->request->post['db_driver'], html_entity_decode($this->request->post['db_hostname'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_username'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_database'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_port'], $this->request->post['db_ssl_key'], $this->request->post['db_ssl_cert'], $this->request->post['db_ssl_ca']);
} catch (\Exception $e) {
$json['warning'] = $e->getMessage();
$json['error']['warning'] = $e->getMessage();
}
}

if (!$this->request->post['username']) {
$json['username'] = $this->language->get('error_username');
$json['error']['username'] = $this->language->get('error_username');
}

if (!oc_validate_email($this->request->post['email'])) {
$json['email'] = $this->language->get('error_email');
$json['error']['email'] = $this->language->get('error_email');
}

if (!$this->request->post['password']) {
$json['password'] = $this->language->get('error_password');
$json['error']['password'] = $this->language->get('error_password');
}

if (!is_writable(DIR_OPENCART . 'config.php')) {
$json['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'config.php!';
$json['error']['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'config.php!';
}

if (!is_writable(DIR_OPENCART . 'admin/config.php')) {
$json['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'admin/config.php!';
$json['error']['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'admin/config.php!';
}

if (!$json) {
Expand Down
2 changes: 2 additions & 0 deletions upload/install/view/template/install/step_2.twig
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ $('#form-step-2').on('submit', function(e) {
$('#button-continue').prop('disabled', false);
},
success: function(json) {
console.log(json);
$('.alert-dismissible').remove();
if (json['redirect']) {
Expand Down
44 changes: 33 additions & 11 deletions upload/install/view/template/install/step_3.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="card">
<div class="card-header"><i class="fa-solid fa-cogs"></i> {{ text_step_3 }}</div>
<div class="card-body">
<form id="step-3">
<form id="form-step-3">
<fieldset>
<legend>{{ text_db_connection }}</legend>
<div class="row">
Expand All @@ -26,40 +26,48 @@
<div class="col-md-8 order-md-1">
<div class="row">
<div class="col-12 col-md-6 mb-3">
<label for="input-db-driver" class="form-label">{{ entry_db_driver }}</label> <select name="db_driver" id="input-db-driver" class="form-control">
<label for="input-db-driver" class="form-label">{{ entry_db_driver }}</label>
<select name="db_driver" id="input-db-driver" class="form-control">
{% for driver in drivers %}
<option value="{{ driver.value }}">{{ driver.text }}</option>
{% endfor %}
</select>
<div id="error-db-driver" class="invalid-feedback"></div>
</div>
<div class="col-12 col-md-6 mb-3 required">
<label for="input-db-hostname" class="form-label">{{ entry_db_hostname }}</label> <input type="text" name="db_hostname" value="localhost" placeholder="{{ entry_db_hostname }}" id="input-db-hostname" class="form-control"/>
<label for="input-db-hostname" class="form-label">{{ entry_db_hostname }}</label>
<input type="text" name="db_hostname" value="localhost" placeholder="{{ entry_db_hostname }}" id="input-db-hostname" class="form-control"/>
<div id="error-db-hostname" class="invalid-feedback"></div>
</div>
<div class="col-12 col-md-6 mb-3 required">
<label for="input-db-username" class="form-label">{{ entry_db_username }}</label> <input type="text" name="db_username" value="root" placeholder="{{ entry_db_username }}" id="input-db-username" class="form-control"/>
<label for="input-db-username" class="form-label">{{ entry_db_username }}</label>
<input type="text" name="db_username" value="root" placeholder="{{ entry_db_username }}" id="input-db-username" class="form-control"/>
<div id="error-db-username" class="invalid-feedback"></div>
</div>
<div class="col-12 col-md-6 mb-3">
<label for="input-db-password" class="form-label">{{ entry_db_password }}</label> <input type="password" name="db_password" value="" placeholder="{{ entry_db_password }}" id="input-db-password" class="form-control" autocomplete="new-password"/>
<label for="input-db-password" class="form-label">{{ entry_db_password }}</label>
<input type="password" name="db_password" value="" placeholder="{{ entry_db_password }}" id="input-db-password" class="form-control" autocomplete="new-password"/>
</div>
<div class="col-12 col-md-6 mb-3 required">
<label for="input-db-database" class="form-label">{{ entry_db_database }}</label> <input type="text" name="db_database" value="" placeholder="{{ entry_db_database }}" id="input-db-database" class="form-control"/>
<label for="input-db-database" class="form-label">{{ entry_db_database }}</label>
<input type="text" name="db_database" value="" placeholder="{{ entry_db_database }}" id="input-db-database" class="form-control"/>
<div id="error-db-database" class="invalid-feedback"></div>
</div>
<div class="col-12 col-md-6 mb-3">
<label for="input-db-prefix" class="form-label">{{ entry_db_prefix }}</label> <input type="text" name="db_prefix" value="oc_" placeholder="{{ entry_db_prefix }}" id="input-db-prefix" class="form-control"/>
<label for="input-db-prefix" class="form-label">{{ entry_db_prefix }}</label>
<input type="text" name="db_prefix" value="oc_" placeholder="{{ entry_db_prefix }}" id="input-db-prefix" class="form-control"/>
<div id="error-db-prefix" class="invalid-feedback"></div>
</div>
<div class="col-12 col-md-6 mb-3 required">
<label for="input-db-port" class="form-label">{{ entry_db_port }}</label> <input type="text" name="db_port" value="3306" placeholder="{{ entry_db_port }}" id="input-db-port" class="form-control"/>
<label for="input-db-port" class="form-label">{{ entry_db_port }}</label>
<input type="text" name="db_port" value="3306" placeholder="{{ entry_db_port }}" id="input-db-port" class="form-control"/>
<div id="error-db-port" class="invalid-feedback"></div>
</div>
<div class="col-12 col-md-6 mb-3 db-advanced">
<label for="input-db-advanced" class="form-label">{{ entry_db_advanced }}</label>
<div class="form-check form-switch form-switch-lg">
<input type="hidden" name="advanced" value="0"/> <input type="checkbox" name="advanced" value="1" id="input-db-advanced" data-bs-toggle="collapse" data-bs-target="#collapse-advanced" class="form-check-input collapsed"/>
<input type="hidden" name="advanced" value="0"/>
<input type="checkbox" name="advanced" value="1" data-bs-toggle="collapse" data-bs-target="#collapse-advanced" class="form-check-input collapsed"/>
</div>
</div>
</div>
Expand Down Expand Up @@ -141,8 +149,10 @@ $('#input-db-driver').trigger('change');
$('#form-step-3').on('submit', function(e) {
e.preventDefault();
var element = this;
$.ajax({
url: 'index.php?route=install/step_2.save&language=' + $('#input-language').val(),
url: 'index.php?route=install/step_3.save&language=' + $('#input-language').val(),
type: 'post',
data: $('#form-step-3').serialize(),
dataType: 'json',
Expand All @@ -153,14 +163,26 @@ $('#form-step-3').on('submit', function(e) {
$('#button-continue').prop('disabled', false);
},
success: function(json) {
console.log(json);
$('.alert-dismissible').remove();
$(element).find('.is-invalid').removeClass('is-invalid');
$(element).find('.invalid-feedback').removeClass('d-block');
if (json['redirect']) {
location = json['redirect'];
}
if (json['error']) {
$('#form-step-2').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
if (json['error']['warning']) {
$('#form-step-3').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error']['warning'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
}
for (key in json['error']) {
$('#input-' + key.replaceAll('_', '-')).addClass('is-invalid').find('.form-control, .form-select, .form-check-input, .form-check-label').addClass('is-invalid');
$('#error-' + key.replaceAll('_', '-')).html(json['error'][key]).addClass('d-block');
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
Expand Down

0 comments on commit eff344c

Please sign in to comment.