Added mail configuration
This commit is contained in:
parent
f2a3bfa9d4
commit
015c6e704c
|
|
@ -114,12 +114,12 @@
|
|||
result = confirm(data['support_error']);
|
||||
if (result) {
|
||||
$('#admin').hide();
|
||||
$('#finish').show();
|
||||
$('#email').show();
|
||||
}
|
||||
}
|
||||
if (!data['connection'] && !data['insert_fail'] && !data['support_error']) {
|
||||
$('#admin').hide();
|
||||
$('#finish').show();
|
||||
$('#email').show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,122 @@
|
|||
<div class="container email" id="email">
|
||||
<div class="initial-display">
|
||||
<p>Email Configuration</p>
|
||||
<form action="EmailConfig.php" method= "POST" id="email-form">
|
||||
<div class="content">
|
||||
<div class="form-container" style="padding: 10%; padding-top: 35px">
|
||||
<input type="hidden" name="mail_driver" value="smtp">
|
||||
|
||||
<div class="control-group" id="mail_host">
|
||||
<label for="mail_host" class="required">Outgoing mail server</label>
|
||||
<input type="text" name="mail_host" class="control" placeholder="smtp.mailtrap.io" data-validation="required">
|
||||
</div>
|
||||
|
||||
<div class="control-group" id="mail_port">
|
||||
<label for="mail_port" class="required">Outgoing mail server port</label>
|
||||
<input type="text" name="mail_port" class="control" placeholder="2525" data-validation="required">
|
||||
</div>
|
||||
|
||||
<div class="control-group" id="mail_encryption">
|
||||
<label for="mail_encryption">Encryption</label>
|
||||
<select name="mail_encryption" class="control">
|
||||
<option value="ssl">SSL</option>
|
||||
<option value="tls">TLS</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="control-group" id="mail_from">
|
||||
<label for="mail_from" class="required">Store email address</label>
|
||||
<input type="text" name="mail_from" class="control" placeholder="store@example.com" data-validation="required">
|
||||
</div>
|
||||
|
||||
<div class="control-group" id="mail_username">
|
||||
<label for="mail_username" class="required">Username</label>
|
||||
<input type="text" name="mail_username" class="control" placeholder="store@example.com" data-validation="required">
|
||||
</div>
|
||||
|
||||
<div class="control-group" id="mail_password">
|
||||
<label for="mail_password" class="required">Password</label>
|
||||
<input type="password" name="mail_password" class="control" data-validation="length required" data-validation-length="min6">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button class="prepare-btn" id="mail-check">Save configuration</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$.validate({});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#email').hide();
|
||||
// process the form
|
||||
$('#email-form').submit(function(event) {
|
||||
$('.control-group').removeClass('has-error'); // remove the error class
|
||||
$('.form-error').remove(); // remove the error text
|
||||
// get the form data
|
||||
var mailformData = {
|
||||
'mail_driver' : $('input[name=mail_driver]').val(),
|
||||
'mail_host' : $('input[name=mail_host]').val(),
|
||||
'mail_port' : $('input[name=mail_port]').val(),
|
||||
'mail_from' : $('input[name=mail_from]').val(),
|
||||
'mail_username' : $('input[name=mail_username]').val(),
|
||||
'mail_password' : $('input[name=mail_password]').val(),
|
||||
'mail_encryption' : $('select[name=mail_encryption]').val(),
|
||||
};
|
||||
|
||||
var EmailTarget = window.location.href.concat('/EmailConfig.php');
|
||||
|
||||
$.ajax({type : 'POST', url : EmailTarget, data : mailformData, dataType : 'json', encode : true})
|
||||
.done(function(data) {
|
||||
if (!data.success) {
|
||||
// handle errors
|
||||
if (data.errors.mail_driver) {
|
||||
$('#mail_driver').addClass('has-error');
|
||||
$('#mail_driver').append('<div class="form-error">' + data.errors.mail_driver + '</div>');
|
||||
}
|
||||
|
||||
if (data.errors.mail_host) {
|
||||
$('#mail_host').addClass('has-error');
|
||||
$('#mail_host').append('<div class="form-error">' + data.errors.mail_host + '</div>');
|
||||
}
|
||||
|
||||
if (data.errors.mail_port) {
|
||||
$('#mail_port').addClass('has-error');
|
||||
$('#mail_port').append('<div class="form-error">' + data.errors.mail_port + '</div>');
|
||||
}
|
||||
|
||||
if (data.errors.mail_encryption) {
|
||||
$('#mail_encryption').addClass('has-error');
|
||||
$('#mail_encryption').append('<div class="form-error">' + data.errors.mail_encryption + '</div>');
|
||||
}
|
||||
|
||||
if (data.errors.mail_from) {
|
||||
$('#mail_from').addClass('has-error');
|
||||
$('#mail_from').append('<div class="form-error">' + data.errors.mail_from + '</div>');
|
||||
}
|
||||
|
||||
if (data.errors.mail_username) {
|
||||
$('#mail_username').addClass('has-error');
|
||||
$('#mail_username').append('<div class="form-error">' + data.errors.mail_username + '</div>');
|
||||
}
|
||||
|
||||
if (data.errors.mail_password) {
|
||||
$('#mail_password').addClass('has-error');
|
||||
$('#mail_password').append('<div class="form-error">' + data.errors.mail_password + '</div>');
|
||||
}
|
||||
} else {
|
||||
$('#admin').hide();
|
||||
$('#email').hide();
|
||||
$('#finish').show();
|
||||
}
|
||||
});
|
||||
// stop the form from submitting the normal way and refreshing the page
|
||||
event.preventDefault();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
// array to hold validation errors
|
||||
$errors = array();
|
||||
|
||||
// array to pass back data
|
||||
$data = array();
|
||||
|
||||
// validate the variables
|
||||
// if any of these variables don't exist, add an error to our $errors array
|
||||
|
||||
if (empty($_POST['mail_driver']))
|
||||
$errors['mail_driver'] = 'Please select the mail driver.';
|
||||
|
||||
if (empty($_POST['mail_host']))
|
||||
$errors['mail_host'] = 'Please enter the hostname for this outgoing mail server.';
|
||||
|
||||
if (empty($_POST['mail_port']))
|
||||
$errors['mail_port'] = 'Please enter the port for this outgoing mail server.';
|
||||
|
||||
if (empty($_POST['mail_encryption']))
|
||||
$errors['mail_encryption'] = 'Please select the encryption method for this outgoing mail server.';
|
||||
|
||||
if (empty($_POST['mail_from']))
|
||||
$errors['mail_from'] = 'Please enter the email address for this store.';
|
||||
|
||||
if (empty($_POST['mail_username']))
|
||||
$errors['mail_username'] = 'Please enter your email address or username.';
|
||||
|
||||
if (empty($_POST['mail_password']))
|
||||
$errors['mail_password'] = 'Please enter the password for this email address.';
|
||||
|
||||
// return a response
|
||||
// if there are any errors in our errors array, return a success boolean of false
|
||||
|
||||
if(!empty($errors)) {
|
||||
// if there are items in our errors array, return those errors
|
||||
$data['success'] = false;
|
||||
$data['errors'] = $errors;
|
||||
|
||||
} else {
|
||||
// if there are no errors process our form, then return a message
|
||||
// show a message of success and provide a true success variable
|
||||
|
||||
// getting env file location
|
||||
$location = str_replace('\\', '/', getcwd());
|
||||
$currentLocation = explode("/", $location);
|
||||
array_pop($currentLocation);
|
||||
array_pop($currentLocation);
|
||||
$desiredLocation = implode("/", $currentLocation);
|
||||
$envFile = $desiredLocation . '/' . '.env';
|
||||
|
||||
// reading env content
|
||||
$data = file($envFile);
|
||||
$keyValueData = [];
|
||||
|
||||
if ($data) {
|
||||
foreach ($data as $line) {
|
||||
$line = preg_replace('/\s+/', '', $line);
|
||||
$rowValues = explode('=', $line);
|
||||
|
||||
if (strlen($line) !== 0) {
|
||||
$keyValueData[$rowValues[0]] = $rowValues[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// inserting form data to empty array
|
||||
$keyValueData['MAIL_DRIVER'] = $_POST["mail_driver"];
|
||||
$keyValueData['MAIL_HOST'] = $_POST["mail_host"];
|
||||
$keyValueData['MAIL_ENCRYPTION'] = $_POST["mail_encryption"];
|
||||
|
||||
$keyValueData['MAIL_USERNAME'] = $_POST["mail_username"];
|
||||
$keyValueData['MAIL_PASSWORD'] = $_POST["mail_password"];
|
||||
$keyValueData['SHOP_MAIL_FROM'] = $_POST["mail_from"];
|
||||
|
||||
// making key/value pair with form-data for env
|
||||
$changedData = [];
|
||||
foreach ($keyValueData as $key => $value) {
|
||||
$changedData[] = $key . '=' . $value;
|
||||
}
|
||||
|
||||
// inserting new form-data to env
|
||||
$changedData = implode(PHP_EOL, $changedData);
|
||||
file_put_contents($envFile, $changedData);
|
||||
|
||||
$data['success'] = true;
|
||||
$data['message'] = 'Success!';
|
||||
}
|
||||
|
||||
// return all our data to an AJAX call
|
||||
echo json_encode($data);
|
||||
|
|
@ -1,29 +1,24 @@
|
|||
<html>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container finish" id="finish">
|
||||
<div class="initial-display">
|
||||
<p>Finish Installment</p>
|
||||
<p>Installation completed</p>
|
||||
<div class="content">
|
||||
<div class="content-container" style="padding: 20px">
|
||||
<span>
|
||||
Bagisto is successfully installed on your system. Click the below button to launch Admin Panel.
|
||||
Bagisto is successfully installed on your system.<br>
|
||||
Click the below button to launch Admin Panel.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="prepare-btn" onclick="finish()">Finish</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<script>
|
||||
|
||||
function finish() {
|
||||
lastIndex = window.location.href.lastIndexOf("/");
|
||||
secondlast = window.location.href.slice(0, lastIndex).lastIndexOf("/");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<div class="container requirement" id="requirement">
|
||||
<div class="initial-display">
|
||||
<p>Requirement</p>
|
||||
<p>Requirements</p>
|
||||
|
||||
<div class="content">
|
||||
<div class="title" style="text-align: center; margin-top: 10px">
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@
|
|||
include __DIR__ . '/Environment.php';
|
||||
include __DIR__ . '/Migration.php';
|
||||
include __DIR__ . '/Admin.php';
|
||||
include __DIR__ . '/Email.php';
|
||||
include __DIR__ . '/Finish.php';
|
||||
|
||||
// including js
|
||||
|
|
|
|||
Loading…
Reference in New Issue