socket and client login and forgot password update

This commit is contained in:
=bhagwanSingh 2025-11-13 17:56:49 +05:30
parent 79eff1a6e3
commit ea574004ce
5 changed files with 243 additions and 11 deletions

View File

@ -1,9 +0,0 @@
version: 2
authtoken: 2gibp9BBceUJDZtNScqH5ivAUTA_2EVNSsmY6HkNYuY6aw7a4
tunnels:
myapp:
proto: http
addr: 3000
hostname: wired-terminally-muskrat.ngrok-free.app
# No bind_tls here!
# Optionally, you can specify 'scheme: https'

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -63,6 +63,9 @@ app.get('/health', (req, res) => {
app.get("/client/login", (req, res) => {
res.render("client_login")
})
app.get("/client/forgot-password", (req, res) => {
res.render("forgot_password")
})
app.get("/live/:projectId", (req, res) => {
const { projectId } = req.params;

View File

@ -220,10 +220,10 @@
<div class="login-card">
<h2>Log in to your account to continue</h2>
<form method="POST" action="/login">
<form>
<input type="email" name="email" placeholder="Enter your email address *" required />
<input type="password" name="password" placeholder="Enter your password *" required />
<a href="/forgot" class="forgot">Forgot password?</a>
<a href="/client/forgot-password" class="forgot">Forgot password?</a>
<button type="submit" class="btn btn-primary">🔒 Log in using password</button>
@ -247,6 +247,50 @@
}
setTheme(getSystemTheme());
document.querySelector("form").addEventListener("submit", async (e) => {
e.preventDefault(); // prevent page reload
const email = e.target.email.value.trim();
const password = e.target.password.value.trim();
if (!email || !password) {
alert("Please enter both email and password");
return;
}
const userDetails = {
email,
password,
};
try {
const res = await fetch("/api/v1/client/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({"userDetails": userDetails}),
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.message || "Login failed");
}
if (data.token) {
// 🟢 Save token
localStorage.setItem("authToken", data.token);
// 🟢 Redirect
window.location.href = "/client/dashboard";
} else {
alert("No token received. Please try again.");
}
} catch (err) {
console.error("❌ Login error:", err);
alert(err.message || "Something went wrong while logging in");
}
});
</script>
</body>

193
views/forgot_password.ejs Normal file
View File

@ -0,0 +1,193 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DocVA | Reset Password</title>
<style>
:root[data-theme="light"] {
--bg: #ffffff;
--text: #111827;
--card-bg: #ffffff;
--border: #e5e7eb;
--btn-bg: #0a0a8f;
--btn-text: #ffffff;
}
:root[data-theme="dark"] {
--bg: #121212;
--text: #f9fafb;
--card-bg: #1e1e1e;
--border: #334155;
--btn-bg: #3b82f6;
--btn-text: #ffffff;
}
body {
background-color: var(--bg);
color: var(--text);
font-family: "Inter", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
transition: background-color 0.3s, color 0.3s;
}
.container {
text-align: center;
width: 100%;
max-width: 380px;
}
.logo {
width: 170px;
margin-bottom: 1.5rem;
transition: opacity 0.3s;
}
.card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 12px;
padding: 2rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
transition: background 0.3s, border-color 0.3s;
}
h2 {
font-size: 1rem;
font-weight: 500;
margin-bottom: 1rem;
}
input {
box-sizing: border-box;
width: 100%;
padding: 0.8rem;
margin-bottom: 1.2rem;
border-radius: 8px;
border: 1px solid var(--border);
background: #fff;
color: #111;
font-size: 0.9rem;
transition: border 0.3s;
}
:root[data-theme="dark"] input {
background: #0f172a;
color: #fff;
border: 1px solid #475569;
}
button {
width: 100%;
background: var(--btn-bg);
color: var(--btn-text);
border: none;
padding: 0.8rem;
border-radius: 8px;
font-size: 0.95rem;
cursor: pointer;
transition: opacity 0.3s;
}
button:hover {
opacity: 0.9;
}
a {
display: block;
margin-top: 1rem;
font-size: 0.85rem;
color: var(--text);
text-decoration: none;
opacity: 0.8;
}
a:hover {
opacity: 1;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<img id="logo" class="logo" src="/public/images/logo-colored-vertical.svg" alt="DocVA Logo" />
<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="#">Go back to login</a>
</form>
</div>
<script>
(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) {
alert("Please enter your 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) {
window.location.href = "/client/login"; // Redirect to reset password page
} 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>
</body>
</html>