Files
Outpost/templates/login.html
2025-12-18 15:16:15 +00:00

545 lines
18 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 | {{ appName }}</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Inter:wght@400;500;600&display=swap');
:root {
--brand-primary: #6366f1;
--brand-hover: #4f46e5;
--brand-success: #10b981;
--brand-error: #ef4444;
--text-main: #0f172a;
--text-muted: #64748b;
--bg-body: #f8fafc;
--border-color: #e2e8f0;
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
--shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
--radius-xl: 2rem;
--radius-lg: 0.75rem;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-body);
background-image:
radial-gradient(at 0% 0%, hsla(253,16%,95%,1) 0, transparent 50%),
radial-gradient(at 100% 0%, hsla(225,39%,90%,1) 0, transparent 50%);
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
overflow: hidden;
}
.login-card {
max-width: 448px;
width: 100%;
background: #ffffff;
border-radius: var(--radius-xl);
box-shadow: var(--shadow-xl);
border: 1px solid var(--border-color);
display: flex;
flex-direction: column;
overflow: hidden;
}
.card-content {
padding: 2.5rem;
display: flex;
flex-direction: column;
}
.brand-header {
display: flex;
align-items: center;
gap: 0.75rem;
margin-bottom: 2rem;
}
.brand-icon {
width: 32px;
height: 32px;
background: var(--brand-primary);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: white;
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
font-size: 0.875rem;
}
.brand-name {
font-family: 'Space Grotesk', sans-serif;
font-size: 1.25rem;
font-weight: 700;
color: var(--text-main);
letter-spacing: -0.025em;
}
h2 {
font-family: 'Space Grotesk', sans-serif;
font-size: 1.875rem;
font-weight: 700;
color: var(--text-main);
margin-bottom: 0.5rem;
letter-spacing: -0.025em;
}
.description {
color: var(--text-muted);
font-size: 0.875rem;
margin-bottom: 2rem;
line-height: 1.5;
}
.form-group {
margin-bottom: 1.5rem;
}
.input-container {
display: flex;
align-items: center;
background: #ffffff;
border: 2px solid var(--border-color);
border-radius: var(--radius-lg);
padding: 0 1rem;
transition: all 0.3s ease;
}
.input-container:focus-within {
border-color: var(--brand-primary);
box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}
.input-container i {
color: var(--text-muted);
margin-right: 0.75rem;
font-size: 1rem;
}
input {
width: 100%;
border: none;
outline: none;
padding: 0.875rem 0;
font-size: 1rem;
color: var(--text-main);
background: transparent;
}
.btn {
width: 100%;
padding: 1rem;
border-radius: var(--radius-lg);
border: none;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
transition: all 0.3s ease;
}
.btn-primary {
background: var(--brand-primary);
color: white;
box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}
.btn-primary:hover:not(:disabled) {
background: var(--brand-hover);
transform: translateY(-1px);
}
.btn-primary:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.btn-text {
background: transparent;
color: var(--text-muted);
border: none;
font-size: 0.875rem;
font-weight: 500;
margin-top: 1rem;
cursor: pointer;
transition: color 0.2s;
}
.btn-text:hover {
color: var(--brand-primary);
}
.back-link {
display: inline-flex;
align-items: center;
gap: 0.5rem;
color: var(--text-muted);
font-size: 0.75rem;
font-weight: 700;
text-decoration: none;
margin-bottom: 1.5rem;
cursor: pointer;
transition: color 0.2s;
}
.back-link:hover {
color: var(--brand-primary);
}
.identity-chip {
display: flex;
align-items: center;
gap: 0.5rem;
background: var(--bg-body);
border: 1px solid var(--border-color);
padding: 0.375rem 0.75rem;
border-radius: 0.5rem;
font-size: 0.75rem;
color: var(--text-muted);
width: fit-content;
margin-bottom: 1.5rem;
}
.hidden { display: none !important; }
.error-box {
background: #fef2f2;
border-left: 4px solid var(--brand-error);
color: #b91c1c;
padding: 0.75rem;
border-radius: 0 0.5rem 0.5rem 0;
font-size: 0.75rem;
margin-bottom: 1.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.success-state {
text-align: center;
padding: 1rem 0;
}
.success-icon {
width: 64px;
height: 64px;
background: #ecfdf5;
color: var(--brand-success);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
margin: 0 auto 1.5rem;
}
.step-transition {
animation: fadeInScale 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fadeInScale {
from { opacity: 0; transform: scale(0.99) translateY(5px); }
to { opacity: 1; transform: scale(1) translateY(0); }
}
.loader {
width: 18px;
height: 18px;
border: 2px solid rgba(255,255,255,0.3);
border-top-color: #fff;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.toggle-btn {
background: none;
border: none;
color: var(--text-muted);
cursor: pointer;
padding: 0.5rem;
}
</style>
</head>
<body>
<div class="login-card">
<div class="card-content">
<!-- Brand -->
<div class="brand-header">
<div class="brand-icon">
<i class="fa-solid fa-key"></i>
</div>
<span class="brand-name">{{ appName }}</span>
</div>
<!-- Stage 1: Identity -->
<div id="stage1" class="step-transition">
<h2>Login</h2>
<p class="description">Please enter your email or username to log in</p>
<form id="emailForm" onsubmit="toStage2(event)">
<div class="form-group">
<div class="input-container">
<i class="fa-solid fa-envelope"></i>
<input type="text" id="email" required placeholder="name@company.com">
</div>
</div>
<button type="submit" id="nextBtn" class="btn btn-primary">
<span id="nextLoader" class="loader hidden"></span>
<span id="nextText">Next</span>
<i class="fa-solid fa-arrow-right" style="font-size: 0.75rem; opacity: 0.7;" id="nextIcon"></i>
</button>
</form>
</div>
<!-- Stage 2: Verification -->
<div id="stage2" class="step-transition hidden">
<div class="back-link" onclick="backToStage1()">
<i class="fa-solid fa-chevron-left"></i>
Change account
</div>
<h2>Password</h2>
<div class="identity-chip">
<i class="fa-solid fa-user-circle"></i>
<span id="displayEmail"></span>
</div>
<form id="passwordForm" onsubmit="handleLogin(event)">
<div class="form-group">
<div class="input-container">
<i class="fa-solid fa-lock"></i>
<input type="password" id="password" required placeholder="Enter password" autocomplete="current-password">
<button type="button" class="toggle-btn" onclick="togglePassword()">
<i id="eyeIcon" class="fa-solid fa-eye"></i>
</button>
</div>
</div>
<div id="passwordError" class="error-box hidden">
<i class="fa-solid fa-circle-exclamation"></i>
<span>Invalid password</span>
</div>
<div style="display: flex; flex-direction: column; align-items: center;">
<button type="submit" id="loginBtn" class="btn btn-primary">
<span id="loginLoader" class="loader hidden"></span>
<span id="loginText">Login</span>
</button>
<button type="button" class="btn-text" onclick="toResetPassword()">
Forgot your password?
</button>
</div>
</form>
</div>
<!-- Stage 3: Reset Password -->
<div id="stage3" class="step-transition hidden">
<div class="back-link" onclick="backToStage2()">
<i class="fa-solid fa-chevron-left"></i>
Back to login
</div>
<h2>Reset Password</h2>
<p class="description">We'll send a recovery link to your registered email address.</p>
<div class="identity-chip">
<i class="fa-solid fa-paper-plane"></i>
<span id="resetEmailDisplay"></span>
</div>
<form id="resetForm" onsubmit="handleReset(event)">
<button type="submit" id="resetBtn" class="btn btn-primary">
<span id="resetLoader" class="loader hidden"></span>
<span id="resetText">Send Reset Link</span>
</button>
</form>
</div>
<!-- Success Stage -->
<div id="successStage" class="step-transition hidden">
<div class="success-state">
<div class="success-icon">
<i class="fa-solid fa-check"></i>
</div>
<h2>Check your email</h2>
<p class="description">We've sent recovery instructions to your inbox. Please check your spam folder if you don't see it.</p>
<button class="btn btn-primary" onclick="backToStage1()">
Return to login
</button>
</div>
</div>
</div>
</div>
<script>
const stages = {
1: document.getElementById('stage1'),
2: document.getElementById('stage2'),
3: document.getElementById('stage3'),
success: document.getElementById('successStage')
};
const emailInput = document.getElementById('email');
const passwordInput = document.getElementById('password');
const displayEmail = document.getElementById('displayEmail');
const resetEmailDisplay = document.getElementById('resetEmailDisplay');
const passwordError = document.getElementById('passwordError');
async function sendLoginRequest(email, password) {
try {console.log("attempting to fetch")
const response = await fetch("{{ url_for('handleLogin') }}", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ "username": email, "password": password }),
});
if (!response.ok) {
return false;
}
const result = await response.json();
if (result != "Invalid username or password") {
document.cookie = `auth_token=${result}`;
window.location.reload();
} else {
return false;
}
} catch (error) {
console.error(error.message)
}
return false
}
function switchStage(to) {
Object.values(stages).forEach(s => s.classList.add('hidden'));
stages[to].classList.remove('hidden');
}
function toStage2(e) {
e.preventDefault();
const btn = document.getElementById('nextBtn');
const loader = document.getElementById('nextLoader');
const text = document.getElementById('nextText');
const icon = document.getElementById('nextIcon');
btn.disabled = true;
loader.classList.remove('hidden');
icon.classList.add('hidden');
text.innerText = 'Verifying...';
setTimeout(() => {
const email = emailInput.value;
displayEmail.innerText = email;
resetEmailDisplay.innerText = email;
switchStage(2);
passwordError.classList.add('hidden');
passwordInput.value = '';
passwordInput.focus();
btn.disabled = false;
loader.classList.add('hidden');
icon.classList.remove('hidden');
text.innerText = 'Next';
}, 600);
}
function toResetPassword() {
switchStage(3);
}
function handleReset(e) {
e.preventDefault();
const btn = document.getElementById('resetBtn');
const loader = document.getElementById('resetLoader');
const text = document.getElementById('resetText');
btn.disabled = true;
loader.classList.remove('hidden');
text.innerText = 'Sending...';
setTimeout(() => {
switchStage('success');
btn.disabled = false;
loader.classList.add('hidden');
text.innerText = 'Send Reset Link';
}, 1500);
}
function backToStage1() {
switchStage(1);
emailInput.focus();
}
function backToStage2() {
switchStage(2);
passwordInput.focus();
}
function togglePassword() {
const eyeIcon = document.getElementById('eyeIcon');
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
eyeIcon.classList.replace('fa-eye', 'fa-eye-slash');
} else {
passwordInput.type = 'password';
eyeIcon.classList.replace('fa-eye-slash', 'fa-eye');
}
}
async function handleLogin(e) {
e.preventDefault();
const btn = document.getElementById('loginBtn');
const loader = document.getElementById('loginLoader');
const text = document.getElementById('loginText');
const pass = passwordInput.value.trim();
if (!pass) return;
passwordError.classList.add('hidden');
btn.disabled = true;
loader.classList.remove('hidden');
text.innerText = 'Unlocking...';
const loginSuccessful = await sendLoginRequest(emailInput.value, pass);
setTimeout(() => {
if (loginSuccessful) {
text.innerText = 'Welcome back';
btn.style.backgroundColor = 'var(--brand-success)';
setTimeout(() => location.reload(), 1000);
} else {
passwordError.classList.remove('hidden');
btn.disabled = false;
loader.classList.add('hidden');
text.innerText = 'Login';
}
}, 1000);
}
</script>
</body>
</html>