Files
rothbard/templates/login.html
2026-01-29 20:51:14 -08:00

71 lines
2.7 KiB
HTML

{% extends 'base.html' %}
{% block content %}
<div class="flex justify-center py-8">
<div class="w-full max-w-md p-8 space-y-6 bg-white rounded-xl shadow-lg">
<h1 class="text-2xl font-bold text-center text-gray-800">Secure Access</h1>
<div class="bg-blue-50 border border-blue-200 text-blue-700 px-4 py-3 rounded-lg mb-4">
<p>If you don't have a user account, or need to reset your password, send an email to <a href="mailto:office@rothbardlawgroup.com" class="underline">office@rothbardlawgroup.com</a>.</p>
</div>
<form id="login-form" class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Email Address</label>
<input id="email" type="email" required class="w-full border rounded-lg p-2 login-input" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Password</label>
<input id="password" type="password" required class="w-full border rounded-lg p-2 login-input" />
</div>
<button type="submit" class="w-full bg-blue-500 text-blue-100 py-2 rounded-lg login-button">Sign In</button>
<p id="error" class="text-sm text-red-600 mt-2 hidden"></p>
</form>
</div>
</div>
<!-- Firebase App (the core Firebase SDK) -->
<script src="https://www.gstatic.com/firebasejs/12.4.0/firebase-app-compat.js"></script>
<!-- Firebase Auth -->
<script src="https://www.gstatic.com/firebasejs/12.4.0/firebase-auth-compat.js"></script>
<script>
// Initialize Firebase configuration from template
window.FIREBASE_CONFIG = {{ firebase_config|tojson }};
const app = firebase.initializeApp(window.FIREBASE_CONFIG || {});
const auth = firebase.auth();
const form = document.getElementById('login-form');
const email = document.getElementById('email');
const password = document.getElementById('password');
const err = document.getElementById('error');
form.addEventListener('submit', async (e) => {
e.preventDefault();
err.classList.add('hidden');
try {
const cred = await auth.signInWithEmailAndPassword(email.value, password.value);
const idToken = await cred.user.getIdToken();
const res = await fetch('/session_login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ idToken })
});
if (!res.ok) {
throw new Error('Session exchange failed');
}
const data = await res.json();
if (data.requires_password_reset) {
window.location.href = '/require-password-reset';
} else {
window.location.href = '/';
}
} catch (e) {
err.textContent = e.message || 'Authentication failed';
err.classList.remove('hidden');
}
});
</script>
{% endblock %}