Files
vitfit-r2/V2/app/public/index.html
T
2026-06-13 20:42:08 -04:00

110 lines
4.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VitFit — Sign In</title>
<link rel="manifest" href="/manifest.json">
<link rel="stylesheet" href="/styles/base.css">
<link rel="stylesheet" href="/styles/layout.css">
<link rel="stylesheet" href="/styles/components.css">
</head>
<body>
<div class="login-page">
<div class="card login-card">
<div class="login-logo">
<img id="banner-logo" src="/icons/icon-192.png" alt="VitFit" style="width:64px;height:64px;" onerror="this.style.display='none'">
<h1 id="app-name" class="login-title">VitFit</h1>
</div>
<form id="login-form" novalidate>
<div class="form-group">
<label class="form-label" for="identifier">Email or Username</label>
<input class="form-input" type="text" id="identifier" name="identifier" autocomplete="username" required>
</div>
<div class="form-group">
<label class="form-label" for="password">Password</label>
<input class="form-input" type="password" id="password" name="password" autocomplete="current-password" required>
</div>
<div id="login-error" class="form-error" style="display:none;"></div>
<button class="btn btn-primary btn-full" type="submit" id="login-btn">Sign In</button>
</form>
</div>
</div>
<script src="/js/core.js"></script>
<script>
(async () => {
// If already authenticated, skip to dashboard
const user = Page.currentUser();
if (user) {
window.location.href = user.role === 'Client' ? '/my-workouts.html' : '/dashboard.html';
return;
}
// Try kiosk device token
const ok = await Auth.tryDeviceLogin();
if (ok) {
const u = Page.currentUser();
window.location.href = u?.role === 'Client' ? '/my-workouts.html' : '/dashboard.html';
return;
}
// Load org branding without auth
try {
const res = await fetch('/api/v1/org/branding/public');
if (res.ok) {
const { data } = await res.json();
Branding.apply(data);
const titleEl = document.getElementById('app-name');
if (titleEl && data.appName) titleEl.textContent = data.appName;
const logoEl = document.getElementById('banner-logo');
if (logoEl && data.logoPath) { logoEl.src = data.logoPath; logoEl.style.display = ''; }
}
} catch {}
const form = document.getElementById('login-form');
const errEl = document.getElementById('login-error');
const loginBtn = document.getElementById('login-btn');
form.addEventListener('submit', async (e) => {
e.preventDefault();
errEl.style.display = 'none';
loginBtn.disabled = true;
loginBtn.textContent = 'Signing in…';
const identifier = document.getElementById('identifier').value.trim();
const password = document.getElementById('password').value;
try {
const res = await fetch('/api/v1/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ identifier, password }),
});
const body = await res.json();
if (!res.ok) {
errEl.textContent = body.message || 'Sign in failed.';
errEl.style.display = 'block';
return;
}
Auth.setJwt(body.data.jwt);
if (body.data.deviceToken) Auth.setDeviceToken(body.data.deviceToken);
const u = Page.currentUser();
window.location.href = u?.role === 'Client' ? '/my-workouts.html' : '/dashboard.html';
} catch {
errEl.textContent = 'Network error. Please try again.';
errEl.style.display = 'block';
} finally {
loginBtn.disabled = false;
loginBtn.textContent = 'Sign In';
}
});
})();
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').catch(() => {});
}
</script>
</body>
</html>