fix landing page
This commit is contained in:
@@ -15,16 +15,18 @@
|
||||
<p>Manage team presence and parking assignments</p>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; flex-direction: column; gap: 1rem;">
|
||||
<a href="/login" class="btn btn-dark btn-full">Sign In</a>
|
||||
<a href="/register" class="btn btn-secondary btn-full">Create Account</a>
|
||||
<div id="authButtons" style="display: flex; flex-direction: column; gap: 1rem;">
|
||||
<!-- Buttons will be populated by JavaScript based on auth mode -->
|
||||
<div class="loading">Loading...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Redirect if already logged in (JWT token or Authelia)
|
||||
async function checkAndRedirect() {
|
||||
async function init() {
|
||||
const buttonsDiv = document.getElementById('authButtons');
|
||||
|
||||
// Check if already authenticated
|
||||
// Check JWT token first
|
||||
if (localStorage.getItem('access_token')) {
|
||||
window.location.href = '/presence';
|
||||
@@ -33,15 +35,56 @@
|
||||
|
||||
// Check Authelia (backend will read headers)
|
||||
try {
|
||||
const response = await fetch('/api/auth/me');
|
||||
if (response.ok) {
|
||||
const meResponse = await fetch('/api/auth/me');
|
||||
if (meResponse.ok) {
|
||||
window.location.href = '/presence';
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Not authenticated, stay on landing
|
||||
// Not authenticated, continue
|
||||
}
|
||||
|
||||
// Get auth configuration
|
||||
try {
|
||||
const configResponse = await fetch('/api/auth/config');
|
||||
const config = await configResponse.json();
|
||||
|
||||
if (config.authelia_enabled) {
|
||||
// Authelia mode: Login goes to Authelia, Register goes to external portal
|
||||
let buttons = '';
|
||||
|
||||
if (config.login_url) {
|
||||
// Redirect to Authelia login with return URL
|
||||
const returnUrl = encodeURIComponent(window.location.origin + '/presence');
|
||||
buttons += `<a href="${config.login_url}?rd=${returnUrl}" class="btn btn-dark btn-full">Sign In</a>`;
|
||||
} else {
|
||||
// No login URL configured - just try to access the app (Authelia will intercept)
|
||||
buttons += `<a href="/presence" class="btn btn-dark btn-full">Sign In</a>`;
|
||||
}
|
||||
|
||||
if (config.registration_url) {
|
||||
buttons += `<a href="${config.registration_url}" class="btn btn-secondary btn-full" target="_blank">Create Account</a>`;
|
||||
buttons += `<p class="auth-footer" style="margin-top: 0.5rem; text-align: center; font-size: 0.875rem; color: #666;">Registration requires admin approval</p>`;
|
||||
}
|
||||
|
||||
buttonsDiv.innerHTML = buttons;
|
||||
} else {
|
||||
// Standalone mode: Local login and registration
|
||||
buttonsDiv.innerHTML = `
|
||||
<a href="/login" class="btn btn-dark btn-full">Sign In</a>
|
||||
<a href="/register" class="btn btn-secondary btn-full">Create Account</a>
|
||||
`;
|
||||
}
|
||||
} catch (e) {
|
||||
// Fallback to standalone mode
|
||||
buttonsDiv.innerHTML = `
|
||||
<a href="/login" class="btn btn-dark btn-full">Sign In</a>
|
||||
<a href="/register" class="btn btn-secondary btn-full">Create Account</a>
|
||||
`;
|
||||
}
|
||||
}
|
||||
checkAndRedirect();
|
||||
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -37,11 +37,30 @@
|
||||
|
||||
<script src="/js/api.js"></script>
|
||||
<script>
|
||||
// Redirect if already logged in
|
||||
if (api.isAuthenticated()) {
|
||||
window.location.href = '/presence';
|
||||
async function init() {
|
||||
// Redirect if already logged in
|
||||
if (api.isAuthenticated()) {
|
||||
window.location.href = '/presence';
|
||||
return;
|
||||
}
|
||||
|
||||
// Check auth mode - if Authelia enabled, redirect to Authelia login
|
||||
try {
|
||||
const configResponse = await fetch('/api/auth/config');
|
||||
const config = await configResponse.json();
|
||||
|
||||
if (config.authelia_enabled && config.login_url) {
|
||||
const returnUrl = encodeURIComponent(window.location.origin + '/presence');
|
||||
window.location.href = `${config.login_url}?rd=${returnUrl}`;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Continue with local login
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
@@ -42,11 +42,29 @@
|
||||
|
||||
<script src="/js/api.js"></script>
|
||||
<script>
|
||||
// Redirect if already logged in
|
||||
if (api.isAuthenticated()) {
|
||||
window.location.href = '/presence';
|
||||
async function init() {
|
||||
// Redirect if already logged in
|
||||
if (api.isAuthenticated()) {
|
||||
window.location.href = '/presence';
|
||||
return;
|
||||
}
|
||||
|
||||
// Check auth mode - if Authelia enabled, redirect to external registration portal
|
||||
try {
|
||||
const configResponse = await fetch('/api/auth/config');
|
||||
const config = await configResponse.json();
|
||||
|
||||
if (config.authelia_enabled && config.registration_url) {
|
||||
window.location.href = config.registration_url;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Continue with local registration
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
document.getElementById('registerForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user