added burger menu with admin page and user invitation link generation
This commit is contained in:
@@ -0,0 +1,368 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Baby Monitor - Register</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
|
||||
padding: 40px;
|
||||
max-width: 450px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
margin-bottom: 10px;
|
||||
font-size: 28px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: #666;
|
||||
margin-bottom: 30px;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #444;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
font-size: 16px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.button {
|
||||
width: 100%;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 14px;
|
||||
border-radius: 6px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ffebee;
|
||||
border-left: 4px solid #f44336;
|
||||
color: #c62828;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.error.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.success {
|
||||
background: #e8f5e9;
|
||||
border-left: 4px solid #4caf50;
|
||||
color: #2e7d32;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.success.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
border: 3px solid #f3f3f3;
|
||||
border-top: 3px solid #667eea;
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto 20px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background: #e7f3ff;
|
||||
border-left: 4px solid #2196F3;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.password-requirements {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.password-requirements ul {
|
||||
margin: 5px 0 0 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="loadingContainer" class="loading-container">
|
||||
<div class="spinner"></div>
|
||||
<p style="color: #666;">Validating invitation...</p>
|
||||
</div>
|
||||
|
||||
<div id="registerContainer" class="hidden">
|
||||
<h1>🎉 Create Your Account</h1>
|
||||
<p class="subtitle">Complete the registration to get started</p>
|
||||
|
||||
<div id="error" class="error"></div>
|
||||
<div id="success" class="success"></div>
|
||||
|
||||
<form id="registerForm" onsubmit="handleRegister(event)">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
minlength="3"
|
||||
autocomplete="username"
|
||||
placeholder="Choose a username"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
minlength="8"
|
||||
autocomplete="new-password"
|
||||
placeholder="Choose a strong password"
|
||||
>
|
||||
<div class="password-requirements">
|
||||
<ul>
|
||||
<li>At least 8 characters long</li>
|
||||
<li>Mix of letters, numbers recommended</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirmPassword">Confirm Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
required
|
||||
minlength="8"
|
||||
autocomplete="new-password"
|
||||
placeholder="Re-enter your password"
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button" id="submitBtn">
|
||||
Create Account
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="invalidTokenContainer" class="hidden">
|
||||
<h1>⚠️ Invalid Invitation</h1>
|
||||
<p class="subtitle">This invitation link is invalid or has expired</p>
|
||||
<div class="info-box">
|
||||
This could mean:
|
||||
<ul style="margin: 10px 0 0 20px; color: #555;">
|
||||
<li>The invitation has already been used</li>
|
||||
<li>The invitation has expired (24 hours)</li>
|
||||
<li>The invitation link is incorrect</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p style="text-align: center; color: #666; margin-top: 20px;">
|
||||
Please contact an administrator for a new invitation link.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let invitationToken = null;
|
||||
|
||||
// Extract token from URL query parameters
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
invitationToken = urlParams.get('token');
|
||||
|
||||
// Validate token on page load
|
||||
window.addEventListener('DOMContentLoaded', async () => {
|
||||
if (!invitationToken) {
|
||||
showInvalidToken();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Verify the invitation token
|
||||
const response = await fetch(`/api/verify-invitation?token=${encodeURIComponent(invitationToken)}`);
|
||||
|
||||
if (response.ok) {
|
||||
showRegisterForm();
|
||||
} else {
|
||||
showInvalidToken();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error validating invitation:', error);
|
||||
showInvalidToken();
|
||||
}
|
||||
});
|
||||
|
||||
function showRegisterForm() {
|
||||
document.getElementById('loadingContainer').classList.add('hidden');
|
||||
document.getElementById('registerContainer').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function showInvalidToken() {
|
||||
document.getElementById('loadingContainer').classList.add('hidden');
|
||||
document.getElementById('invalidTokenContainer').classList.remove('hidden');
|
||||
}
|
||||
|
||||
async function handleRegister(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const confirmPassword = document.getElementById('confirmPassword').value;
|
||||
const errorDiv = document.getElementById('error');
|
||||
const successDiv = document.getElementById('success');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
// Clear previous messages
|
||||
errorDiv.classList.remove('show');
|
||||
successDiv.classList.remove('show');
|
||||
|
||||
// Validate passwords match
|
||||
if (password !== confirmPassword) {
|
||||
errorDiv.textContent = 'Passwords do not match!';
|
||||
errorDiv.classList.add('show');
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable submit button
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = 'Creating Account...';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: username,
|
||||
password: password,
|
||||
invitation_token: invitationToken,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
// Store the access token and username
|
||||
localStorage.setItem('access_token', data.access_token);
|
||||
localStorage.setItem('username', data.username);
|
||||
|
||||
// Show success message
|
||||
successDiv.textContent = 'Account created successfully! Redirecting...';
|
||||
successDiv.classList.add('show');
|
||||
|
||||
// Redirect to home page after a brief delay
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 1500);
|
||||
} else {
|
||||
errorDiv.textContent = data.detail || 'Registration failed. Please try again.';
|
||||
errorDiv.classList.add('show');
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = 'Create Account';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error);
|
||||
errorDiv.textContent = 'An error occurred. Please try again.';
|
||||
errorDiv.classList.add('show');
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = 'Create Account';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user