fix registration

This commit is contained in:
Thanakorn S
2026-05-13 16:15:19 +07:00
parent 511360faa2
commit 4433ef184e
3 changed files with 53 additions and 18 deletions
+11 -9
View File
@@ -85,6 +85,9 @@ class mailer{
"input" => $input
]);
// When silent=true, return false on failure instead of calling exit().
$silent = !empty($input['silent']);
$revise = [];
$revise["subject"] = $input["subject"];
$revise["message"] = $input["message"];
@@ -141,18 +144,17 @@ class mailer{
$mail->AltBody = $revise["message"];
$mail->send();
}
return true;
}
catch (phpmailerException $e) {
$answer = [];
$answer["success"] = 0;
$answer["message"] = "<b>Error1</b>: ".nl2br($e->errorMessage());
exit(json_encode($answer));
$err = "<b>Error1</b>: " . nl2br($e->errorMessage());
if ($silent) { error_log('[mailer] ' . strip_tags($err)); return false; }
exit(json_encode(["success" => 0, "message" => $err]));
}
catch (Exception $e) {
$answer = [];
$answer["success"] = 0;
$answer["message"] = "<b>Error2</b>: ".nl2br($mail->ErrorInfo);
exit(json_encode($answer));
$err = "<b>Error2</b>: " . nl2br($mail->ErrorInfo);
if ($silent) { error_log('[mailer] ' . strip_tags($err)); return false; }
exit(json_encode(["success" => 0, "message" => $err]));
}
}
+15 -7
View File
@@ -173,16 +173,16 @@ try {
. rtrim($server_url, '/');
$verify_url = $base_url . '/login/verify.php?token=' . $token;
// ── Step 14: Send verification email via system SMTP ─────────────────────
// Uses $SMTP from config.php (system-level, not company SMTP) because the
// user does not have a company yet at registration time.
// If the mailer fails it exits internally with its own error JSON response.
// ── Step 14: Send verification email (non-fatal) ─────────────────────────
// silent=true means the mailer returns false on failure instead of calling
// exit() — so the account is always created even if SMTP is unavailable.
require_once $include_url . 'assets/utils/module/mailer.php';
$mailer = new mailer(['pdo1' => $pdo1]);
$mailer->send_email([
$mailer = new mailer(['pdo1' => $pdo1]);
$mail_sent = $mailer->send_email([
'company_id' => 0,
'smtp' => $SMTP,
'silent' => true,
'to' => $email,
'subject' => 'Verify your email — WMS',
'message' => implode("\n", [
@@ -205,7 +205,15 @@ try {
// ── Step 15: Respond ──────────────────────────────────────────────────────
$answer['success'] = 1;
$answer['message'] = 'Account created! Please check your email to verify your account.';
if ($mail_sent) {
$answer['message'] = 'Account created! Please check your email to verify your account.';
} else {
// Email failed (e.g. SMTP blocked on this server) — account still created.
// Return the verify URL so an admin can share it manually, and tell the
// user to contact their administrator.
$answer['message'] = 'Account created! However, the verification email could not be sent. Please contact your administrator to verify your account.';
$answer['verify_url'] = $verify_url;
}
} catch (Exception $e) {
// Unexpected error — log details server-side, return generic message to client
+27 -2
View File
@@ -117,6 +117,21 @@
<p class="text-muted small mb-0">We've sent a verification link to your email address. Click it to activate your account.</p>
</div>
<!-- Fallback: email failed, show verify link directly -->
<div id="verify_link_panel" class="d-none py-3">
<div class="alert alert-warning small mb-3">
<i class="ti ti-alert-triangle me-1"></i>
Account created, but the verification email could not be sent (server email is not configured).
Use the link below to verify your account:
</div>
<div class="input-group">
<input type="text" class="form-control form-control-sm font-monospace" id="verify_link_input" readonly>
<button class="btn btn-sm btn-outline-secondary" onclick="copy_verify_link()">
<i class="ti ti-copy"></i>
</button>
</div>
</div>
<p class="text-center text-muted small mb-0">
Already have an account?
<a href="<?php echo $server_url?>login/index.php" class="link-primary">Sign in</a>
@@ -237,12 +252,22 @@
confirm_password: confirm,
})},
onSuccess: function (r) {
// Hide form, show success panel
$('input, button, .row, .mb-3, .mb-4').hide();
$('#success_panel').removeClass('d-none');
if (r.verify_url) {
$('#verify_link_input').val(r.verify_url);
$('#verify_link_panel').removeClass('d-none');
} else {
$('#success_panel').removeClass('d-none');
}
},
});
}
function copy_verify_link() {
const val = $('#verify_link_input').val();
navigator.clipboard.writeText(val).then(function () {
bootbox.alert('Verification link copied to clipboard.');
});
}
</script>
</body>