106 lines
4.0 KiB
Plaintext
106 lines
4.0 KiB
Plaintext
|
|
<div class="container">
|
|
<div class="logo">
|
|
<img id="logo-img" src="/public/images/logo-white-vertical.svg" alt="DocVA Logo" />
|
|
</div>
|
|
<form class="card">
|
|
<h2>Reset your password</h2>
|
|
<input type="email" placeholder="Enter your email address*" required />
|
|
<button type="submit">Send password reset code</button>
|
|
<a href="/client/login">Go back to login</a>
|
|
</form>
|
|
</div>
|
|
|
|
<script>
|
|
const root = document.documentElement;
|
|
|
|
function setTheme(theme) {
|
|
document.getElementById("logo-img").src =
|
|
theme === "dark"
|
|
? "/public/images/logo-white-vertical.svg"
|
|
: "/public/images/logo-colored-vertical.svg";
|
|
root.setAttribute("data-theme", theme);
|
|
}
|
|
|
|
function getSystemTheme() {
|
|
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
? "dark"
|
|
: "light";
|
|
}
|
|
|
|
setTheme(getSystemTheme());
|
|
|
|
function validateEmail(email) {
|
|
const emailRegex = /^[a-zA-Z0-9](?:[a-zA-Z0-9]*[._-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9]*[-]?[a-zA-Z0-9]+)*\.[a-zA-Z]{2,}$/;
|
|
return emailRegex.test(email);
|
|
}
|
|
|
|
(function () {
|
|
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
|
const logo = document.getElementById("logo");
|
|
|
|
function applyTheme(isDark) {
|
|
const theme = isDark ? "dark" : "light";
|
|
document.documentElement.setAttribute("data-theme", theme);
|
|
// logo.src = isDark ? "/public/images/logo-white-vertical.svg" : "/public/images/logo-colored-vertical.svg";
|
|
}
|
|
|
|
// Initial set
|
|
applyTheme(prefersDark.matches);
|
|
|
|
// Watch for changes
|
|
prefersDark.addEventListener("change", (e) => applyTheme(e.matches));
|
|
})();
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const form = document.querySelector(".card"); // assuming .card wraps your form elements
|
|
const emailInput = form.querySelector("input[type='email']");
|
|
const button = form.querySelector("button");
|
|
|
|
form.addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
|
|
const email = emailInput.value.trim();
|
|
if (!email || !validateEmail(email)) {
|
|
alert("Please enter valid email address.");
|
|
return;
|
|
}
|
|
|
|
button.disabled = true;
|
|
button.textContent = "Sending...";
|
|
|
|
try {
|
|
const response = await fetch("/api/v1/client/forgot-password", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ email }),
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
if(response.success) {
|
|
if(confirm('Please Check your mail inbox for password reset link')) {
|
|
window.location.href = "/client/login"; // Redirect to reset password page
|
|
// console.log(response)
|
|
}
|
|
} else {
|
|
alert(data.message || "Failed to send reset link.");
|
|
}
|
|
} else {
|
|
alert("❌ " + (data.message || "Failed to send reset link."));
|
|
}
|
|
} catch (err) {
|
|
console.error("Error:", err);
|
|
alert("Something went wrong. Please try again later.");
|
|
} finally {
|
|
button.disabled = false;
|
|
button.textContent = "Send password reset code";
|
|
}
|
|
});
|
|
});
|
|
</script>
|