127 lines
5.4 KiB
HTML
127 lines
5.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login | Curio HMS</title>
|
|
<meta name="description" content="Login to Curio HMS — India's WhatsApp-first hospital management platform.">
|
|
<link rel="stylesheet" href="globals.css">
|
|
<link rel="stylesheet" href="login.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
|
|
<script src="tenantLoader.js"></script>
|
|
</head>
|
|
<body class="auth-body">
|
|
<div class="auth-container">
|
|
<div class="auth-card">
|
|
<div class="auth-logo">
|
|
<div class="logo-icon">C</div>
|
|
<h1>Curio</h1>
|
|
</div>
|
|
<h2>Welcome Back</h2>
|
|
<p>Login to manage your clinic OPD and accounts.</p>
|
|
|
|
<div id="loginError" class="auth-error hidden"></div>
|
|
|
|
<form id="loginForm">
|
|
<div class="input-group">
|
|
<label for="loginEmail">Email Address</label>
|
|
<input type="email" id="loginEmail" placeholder="doctor@yourclinic.com" required autocomplete="email">
|
|
</div>
|
|
<div class="input-group">
|
|
<label for="loginPassword">Password</label>
|
|
<input type="password" id="loginPassword" placeholder="••••••••" required autocomplete="current-password">
|
|
</div>
|
|
<button type="submit" class="btn-primary auth-btn" id="loginBtn">
|
|
<span id="loginBtnText">Login to Dashboard</span>
|
|
<span id="loginSpinner" class="btn-spinner hidden">⏳</span>
|
|
</button>
|
|
</form>
|
|
|
|
<p class="auth-footer">New to Curio? <a href="register.html">Register your clinic</a></p>
|
|
<p class="auth-footer" style="font-size:0.78rem; color: var(--text-muted);">
|
|
Demo Admin: <code>admin@curio.app</code> / <code>superadmin</code><br>
|
|
Demo Doctor: <code>doctor@curio.app</code> / <code>password</code><br>
|
|
Demo Pharmacy: <code>pharmacy@curio.app</code> / <code>password</code>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Redirect if already logged in
|
|
(function() {
|
|
const token = localStorage.getItem('curio_token');
|
|
if (token) {
|
|
try {
|
|
const p = JSON.parse(atob(token.split('.')[1]));
|
|
if (p.exp && Date.now() / 1000 < p.exp) {
|
|
if (p.role === 'SUPER_ADMIN') window.location.href = 'super-admin.html';
|
|
else if (p.role === 'PATIENT') window.location.href = 'patient-dashboard.html';
|
|
else window.location.href = 'dashboard.html';
|
|
}
|
|
} catch(_) {}
|
|
}
|
|
})();
|
|
|
|
const form = document.getElementById('loginForm');
|
|
const errBox = document.getElementById('loginError');
|
|
const btn = document.getElementById('loginBtn');
|
|
const btnTxt = document.getElementById('loginBtnText');
|
|
const spin = document.getElementById('loginSpinner');
|
|
|
|
function showError(msg) {
|
|
errBox.textContent = msg;
|
|
errBox.classList.remove('hidden');
|
|
}
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
errBox.classList.add('hidden');
|
|
btn.disabled = true;
|
|
btnTxt.textContent = 'Logging in...';
|
|
spin.classList.remove('hidden');
|
|
|
|
const email = document.getElementById('loginEmail').value.trim();
|
|
const password = document.getElementById('loginPassword').value;
|
|
|
|
try {
|
|
const res = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ email, password }),
|
|
});
|
|
const data = await res.json();
|
|
|
|
if (!res.ok) {
|
|
showError(data.error || 'Login failed. Please try again.');
|
|
return;
|
|
}
|
|
|
|
// Store JWT and user info
|
|
localStorage.setItem('curio_token', data.token);
|
|
localStorage.setItem('userRole', data.role);
|
|
localStorage.setItem('userEmail', email);
|
|
localStorage.setItem('userName', data.name || '');
|
|
if (data.tenantId) localStorage.setItem('Curio_tenant', data.tenantId);
|
|
|
|
// Route by role
|
|
if (data.role === 'SUPER_ADMIN') {
|
|
window.location.href = 'super-admin.html';
|
|
} else if (data.role === 'PATIENT') {
|
|
window.location.href = 'patient-dashboard.html';
|
|
} else {
|
|
window.location.href = 'dashboard.html';
|
|
}
|
|
} catch (err) {
|
|
showError('Network error. Please check your connection.');
|
|
} finally {
|
|
btn.disabled = false;
|
|
btnTxt.textContent = 'Login to Dashboard';
|
|
spin.classList.add('hidden');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|