fix registration
This commit is contained in:
@@ -85,6 +85,9 @@ class mailer{
|
|||||||
"input" => $input
|
"input" => $input
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// When silent=true, return false on failure instead of calling exit().
|
||||||
|
$silent = !empty($input['silent']);
|
||||||
|
|
||||||
$revise = [];
|
$revise = [];
|
||||||
$revise["subject"] = $input["subject"];
|
$revise["subject"] = $input["subject"];
|
||||||
$revise["message"] = $input["message"];
|
$revise["message"] = $input["message"];
|
||||||
@@ -141,18 +144,17 @@ class mailer{
|
|||||||
$mail->AltBody = $revise["message"];
|
$mail->AltBody = $revise["message"];
|
||||||
|
|
||||||
$mail->send();
|
$mail->send();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (phpmailerException $e) {
|
catch (phpmailerException $e) {
|
||||||
$answer = [];
|
$err = "<b>Error1</b>: " . nl2br($e->errorMessage());
|
||||||
$answer["success"] = 0;
|
if ($silent) { error_log('[mailer] ' . strip_tags($err)); return false; }
|
||||||
$answer["message"] = "<b>Error1</b>: ".nl2br($e->errorMessage());
|
exit(json_encode(["success" => 0, "message" => $err]));
|
||||||
exit(json_encode($answer));
|
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
$answer = [];
|
$err = "<b>Error2</b>: " . nl2br($mail->ErrorInfo);
|
||||||
$answer["success"] = 0;
|
if ($silent) { error_log('[mailer] ' . strip_tags($err)); return false; }
|
||||||
$answer["message"] = "<b>Error2</b>: ".nl2br($mail->ErrorInfo);
|
exit(json_encode(["success" => 0, "message" => $err]));
|
||||||
exit(json_encode($answer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,16 +173,16 @@ try {
|
|||||||
. rtrim($server_url, '/');
|
. rtrim($server_url, '/');
|
||||||
$verify_url = $base_url . '/login/verify.php?token=' . $token;
|
$verify_url = $base_url . '/login/verify.php?token=' . $token;
|
||||||
|
|
||||||
// ── Step 14: Send verification email via system SMTP ─────────────────────
|
// ── Step 14: Send verification email (non-fatal) ─────────────────────────
|
||||||
// Uses $SMTP from config.php (system-level, not company SMTP) because the
|
// silent=true means the mailer returns false on failure instead of calling
|
||||||
// user does not have a company yet at registration time.
|
// exit() — so the account is always created even if SMTP is unavailable.
|
||||||
// If the mailer fails it exits internally with its own error JSON response.
|
|
||||||
require_once $include_url . 'assets/utils/module/mailer.php';
|
require_once $include_url . 'assets/utils/module/mailer.php';
|
||||||
|
|
||||||
$mailer = new mailer(['pdo1' => $pdo1]);
|
$mailer = new mailer(['pdo1' => $pdo1]);
|
||||||
$mailer->send_email([
|
$mail_sent = $mailer->send_email([
|
||||||
'company_id' => 0,
|
'company_id' => 0,
|
||||||
'smtp' => $SMTP,
|
'smtp' => $SMTP,
|
||||||
|
'silent' => true,
|
||||||
'to' => $email,
|
'to' => $email,
|
||||||
'subject' => 'Verify your email — WMS',
|
'subject' => 'Verify your email — WMS',
|
||||||
'message' => implode("\n", [
|
'message' => implode("\n", [
|
||||||
@@ -205,7 +205,15 @@ try {
|
|||||||
|
|
||||||
// ── Step 15: Respond ──────────────────────────────────────────────────────
|
// ── Step 15: Respond ──────────────────────────────────────────────────────
|
||||||
$answer['success'] = 1;
|
$answer['success'] = 1;
|
||||||
|
if ($mail_sent) {
|
||||||
$answer['message'] = 'Account created! Please check your email to verify your account.';
|
$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) {
|
} catch (Exception $e) {
|
||||||
// Unexpected error — log details server-side, return generic message to client
|
// Unexpected error — log details server-side, return generic message to client
|
||||||
|
|||||||
+26
-1
@@ -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>
|
<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>
|
</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">
|
<p class="text-center text-muted small mb-0">
|
||||||
Already have an account?
|
Already have an account?
|
||||||
<a href="<?php echo $server_url?>login/index.php" class="link-primary">Sign in</a>
|
<a href="<?php echo $server_url?>login/index.php" class="link-primary">Sign in</a>
|
||||||
@@ -237,12 +252,22 @@
|
|||||||
confirm_password: confirm,
|
confirm_password: confirm,
|
||||||
})},
|
})},
|
||||||
onSuccess: function (r) {
|
onSuccess: function (r) {
|
||||||
// Hide form, show success panel
|
|
||||||
$('input, button, .row, .mb-3, .mb-4').hide();
|
$('input, button, .row, .mb-3, .mb-4').hide();
|
||||||
|
if (r.verify_url) {
|
||||||
|
$('#verify_link_input').val(r.verify_url);
|
||||||
|
$('#verify_link_panel').removeClass('d-none');
|
||||||
|
} else {
|
||||||
$('#success_panel').removeClass('d-none');
|
$('#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>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user