Login , Register ,and onboarding
This commit is contained in:
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
require '../session.php';
|
||||
require '../config.php';
|
||||
require '../include_header.php';
|
||||
|
||||
// Must come from email verification
|
||||
if (empty($_SESSION['onboarding_user_id'])) {
|
||||
header('Location: ' . $server_url . 'login/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Generate CSRF token if not already set
|
||||
if (empty($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||||
}
|
||||
|
||||
$user_name = htmlspecialchars($_SESSION['onboarding_name'] ?? 'there');
|
||||
?>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container py-5" style="max-width:680px;">
|
||||
|
||||
<!-- Header -->
|
||||
<div class="text-center mb-5">
|
||||
<a href="<?php echo $server_url?>login/index.php" class="d-inline-block mb-4">
|
||||
<img src="data:image/svg+xml,%3csvg%20width='62'%20height='67'%20viewBox='0%200%2062%2067'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M30.604%2066.378L0.00805664%2048.1582V35.7825L30.604%2054.0023V66.378Z'%20fill='%23302C4D'/%3e%3cpath%20d='M61.1996%2048.1582L30.604%2066.378V54.0023L61.1996%2035.7825V48.1582Z'%20fill='%23E66239'/%3e%3cpath%20d='M30.5955%200L0%2018.2198V30.5955L30.5955%2012.3757V0Z'%20fill='%23657E92'/%3e%3cpath%20d='M61.191%2018.2198L30.5955%200V12.3757L61.191%2030.5955V18.2198Z'%20fill='%23A3B2BE'/%3e%3cpath%20d='M30.604%2048.8457L0.00805664%2030.6259V18.2498L30.604%2036.47V48.8457Z'%20fill='%23302C4D'/%3e%3cpath%20d='M61.1996%2030.6259L30.604%2048.8457V36.47L61.1996%2018.2498V30.6259Z'%20fill='%23E66239'/%3e%3c/svg%3e"
|
||||
alt="" width="36">
|
||||
<span class="ms-2"><img src="<?php echo $server_url?>assets/images/logo.svg" alt=""></span>
|
||||
</a>
|
||||
<h1 class="h4 mb-1">Welcome, <?php echo $user_name ?>! 👋</h1>
|
||||
<p class="text-muted">Set up your company and email before you get started.</p>
|
||||
</div>
|
||||
|
||||
<!-- Company Info Card -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-body p-5">
|
||||
<h2 class="fs-5 mb-1"><i class="ti ti-building me-2"></i>Company Information</h2>
|
||||
<p class="text-muted small mb-4">This is how your company appears across the system.</p>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Company Name (TH) <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="company_name" placeholder="ชื่อบริษัท" required>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Company Name (EN)</label>
|
||||
<input type="text" class="form-control" id="company_name2" placeholder="Company Name (English)">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Channel Name <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="channel_name" placeholder="e.g. my-shop">
|
||||
<div class="form-text">Unique identifier. Lowercase, no spaces.</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Branch</label>
|
||||
<input type="text" class="form-control" id="branch" placeholder="สำนักงานใหญ่">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Branch No.</label>
|
||||
<input type="text" class="form-control" id="branch_no" placeholder="00000">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Email</label>
|
||||
<input type="email" class="form-control" id="company_email" placeholder="company@example.com">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Phone</label>
|
||||
<input type="text" class="form-control" id="company_phone" placeholder="02-xxx-xxxx">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Card -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-body p-5">
|
||||
|
||||
<div class="d-flex justify-content-between align-items-start mb-1">
|
||||
<h2 class="fs-5 mb-0"><i class="ti ti-mail-cog me-2"></i>SMTP / Email Setting</h2>
|
||||
<span class="badge bg-label-danger">Required</span>
|
||||
</div>
|
||||
<p class="text-muted small mb-3">
|
||||
SMTP is required to send OTP during login.
|
||||
A verification email will be sent when you finish setup.
|
||||
</p>
|
||||
|
||||
<!-- SMTP User Guide (collapsible) -->
|
||||
<div class="mb-4">
|
||||
<a class="small link-primary text-decoration-none" data-bs-toggle="collapse" href="#smtp_guide" role="button">
|
||||
<i class="ti ti-help-circle me-1"></i>How do I get SMTP settings?
|
||||
</a>
|
||||
<div class="collapse mt-3" id="smtp_guide">
|
||||
<div class="border rounded p-4 bg-light small">
|
||||
|
||||
<!-- Gmail -->
|
||||
<div class="mb-4">
|
||||
<div class="fw-semibold mb-2">
|
||||
<i class="ti ti-brand-gmail me-1 text-danger"></i>Gmail
|
||||
</div>
|
||||
<p class="text-muted mb-2">Gmail requires an <strong>App Password</strong> — your regular Gmail password will not work.</p>
|
||||
<ol class="mb-2 ps-3">
|
||||
<li>Go to <a href="https://myaccount.google.com/security" target="_blank">myaccount.google.com/security</a></li>
|
||||
<li>Enable <strong>2-Step Verification</strong> if not already on</li>
|
||||
<li>Search for <strong>App passwords</strong> in the search bar</li>
|
||||
<li>Create a new app password — name it <em>WMS</em></li>
|
||||
<li>Copy the 16-character password shown</li>
|
||||
</ol>
|
||||
<div class="bg-white border rounded p-2 font-monospace small">
|
||||
Host: smtp.gmail.com | Port: 587 | Encryption: TLS
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<!-- Outlook / Office 365 -->
|
||||
<div class="mb-4">
|
||||
<div class="fw-semibold mb-2">
|
||||
<i class="ti ti-brand-office me-1 text-primary"></i>Outlook / Office 365
|
||||
</div>
|
||||
<p class="text-muted mb-2">Use your Microsoft 365 email and password directly. Make sure SMTP AUTH is enabled for your account.</p>
|
||||
<ol class="mb-2 ps-3">
|
||||
<li>Go to <a href="https://admin.microsoft.com" target="_blank">admin.microsoft.com</a></li>
|
||||
<li>Under <strong>Users → Active users</strong>, select the account</li>
|
||||
<li>Go to <strong>Mail → Manage email apps</strong></li>
|
||||
<li>Enable <strong>Authenticated SMTP</strong></li>
|
||||
</ol>
|
||||
<div class="bg-white border rounded p-2 font-monospace small">
|
||||
Host: smtp.office365.com | Port: 587 | Encryption: TLS
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<!-- Yahoo -->
|
||||
<div class="mb-4">
|
||||
<div class="fw-semibold mb-2">
|
||||
<i class="ti ti-mail me-1 text-warning"></i>Yahoo Mail
|
||||
</div>
|
||||
<p class="text-muted mb-2">Yahoo also requires an <strong>App Password</strong>.</p>
|
||||
<ol class="mb-2 ps-3">
|
||||
<li>Go to <a href="https://login.yahoo.com/account/security" target="_blank">Yahoo Account Security</a></li>
|
||||
<li>Enable <strong>Two-step verification</strong></li>
|
||||
<li>Click <strong>Generate app password</strong></li>
|
||||
<li>Select <em>Other App</em>, name it <em>WMS</em>, copy the password</li>
|
||||
</ol>
|
||||
<div class="bg-white border rounded p-2 font-monospace small">
|
||||
Host: smtp.mail.yahoo.com | Port: 587 | Encryption: TLS
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<!-- Generic / cPanel -->
|
||||
<div>
|
||||
<div class="fw-semibold mb-2">
|
||||
<i class="ti ti-server me-1 text-secondary"></i>Web Hosting / cPanel
|
||||
</div>
|
||||
<p class="text-muted mb-2">If your email is hosted with a web provider (e.g. Hostinger, GoDaddy, SiteGround):</p>
|
||||
<ol class="mb-2 ps-3">
|
||||
<li>Log in to your hosting <strong>cPanel</strong></li>
|
||||
<li>Go to <strong>Email Accounts</strong> and create or select an account</li>
|
||||
<li>Click <strong>Connect Devices</strong> to see SMTP details</li>
|
||||
<li>Use those exact host, port and encryption settings</li>
|
||||
</ol>
|
||||
<div class="text-muted">
|
||||
The host is usually <code>mail.yourdomain.com</code> and port is <code>587</code>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Form -->
|
||||
<div class="row g-3">
|
||||
<div class="col-md-8">
|
||||
<label class="form-label">SMTP Host <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="smtp_host" placeholder="e.g. smtp.gmail.com">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Port <span class="text-danger">*</span></label>
|
||||
<select class="form-select" id="smtp_port">
|
||||
<option value="587">587 — TLS</option>
|
||||
<option value="465">465 — SSL</option>
|
||||
<option value="25">25 — Plain</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Username / Email <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="smtp_username" placeholder="your@email.com">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Password <span class="text-danger">*</span></label>
|
||||
<div class="input-group">
|
||||
<input type="password" class="form-control" id="smtp_password" placeholder="SMTP password">
|
||||
<button class="btn btn-outline-secondary toggle-pw" type="button" data-target="smtp_password">
|
||||
<i class="ti ti-eye"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Encryption</label>
|
||||
<div class="d-flex gap-4">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="smtp_encryption" id="enc_tls" value="tls" checked>
|
||||
<label class="form-check-label" for="enc_tls">TLS</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="smtp_encryption" id="enc_ssl" value="ssl">
|
||||
<label class="form-check-label" for="enc_ssl">SSL</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="smtp_encryption" id="enc_none" value="none">
|
||||
<label class="form-check-label" for="enc_none">None</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="d-flex justify-content-end align-items-center">
|
||||
<button class="btn btn-primary px-5" id="btn_finish" onclick="finish_onboarding()">
|
||||
<i class="ti ti-rocket me-1"></i>Finish Setup
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
$(function () {
|
||||
$(document).on('click', '.toggle-pw', function () {
|
||||
const $input = $('#' + $(this).data('target'));
|
||||
const isText = $input.attr('type') === 'text';
|
||||
$input.attr('type', isText ? 'password' : 'text');
|
||||
$(this).find('i').toggleClass('ti-eye ti-eye-off');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function finish_onboarding() {
|
||||
const company_name = $('#company_name').val().trim();
|
||||
const channel_name = $('#channel_name').val().trim();
|
||||
|
||||
if (!company_name || !channel_name) {
|
||||
bootbox.alert('Company name and channel name are required.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$('#smtp_host').val().trim() || !$('#smtp_username').val().trim() || !$('#smtp_password').val()) {
|
||||
bootbox.alert('SMTP host, username and password are required.');
|
||||
return;
|
||||
}
|
||||
|
||||
const $btn = $('#btn_finish');
|
||||
$btn.prop('disabled', true).html('<i class="ti ti-loader-2 me-1"></i>Verifying SMTP…');
|
||||
|
||||
const encryption = $('input[name="smtp_encryption"]:checked').val();
|
||||
|
||||
ajax_request({
|
||||
url: '<?php echo $server_url?>login/api/engine/onboarding.php',
|
||||
autoPrepare: false,
|
||||
data: { json: JSON.stringify({
|
||||
action: 'create',
|
||||
company_name: company_name,
|
||||
company_name2: $('#company_name2').val().trim(),
|
||||
channel_name: channel_name,
|
||||
branch: $('#branch').val().trim() || 'สำนักงานใหญ่',
|
||||
branch_no: $('#branch_no').val().trim() || '00000',
|
||||
email: $('#company_email').val().trim(),
|
||||
phone: $('#company_phone').val().trim(),
|
||||
smtp_host: $('#smtp_host').val().trim(),
|
||||
smtp_port: $('#smtp_port').val(),
|
||||
smtp_username: $('#smtp_username').val().trim(),
|
||||
smtp_password: $('#smtp_password').val(),
|
||||
smtp_encryption: encryption,
|
||||
})},
|
||||
onSuccess: function (r) {
|
||||
bootbox.alert('Setup complete! Please sign in to get started.', function () {
|
||||
window.location.href = '<?php echo $server_url?>login/index.php';
|
||||
});
|
||||
},
|
||||
onError: function (r) {
|
||||
$btn.prop('disabled', false).html('<i class="ti ti-rocket me-1"></i>Finish Setup');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user