fixed centering issue with radius.
Signed-off-by: boris <boris@borishub.co.uk>
This commit is contained in:
Binary file not shown.
@@ -1,51 +0,0 @@
|
|||||||
Username,Password
|
|
||||||
Dylan,MirageAutumnUmbrella7
|
|
||||||
Lawrence,MirageVictoryKingdom5
|
|
||||||
Bryan,EmeraldOrchardLegend3
|
|
||||||
Alan,ThunderOceanDiamond2
|
|
||||||
Frank,XylophoneVictoryHarmony3
|
|
||||||
Logan,NatureSerenityXylophone5
|
|
||||||
Jerry,LighthousePhoenixYellow8
|
|
||||||
Harold,IcebergGlacierTiger8
|
|
||||||
Keith,YachtJourneyGarden4
|
|
||||||
Arthur,VictoryOrchardFlower0
|
|
||||||
Louis,FlowerNebulaNature3
|
|
||||||
Paul,LegendLegendYacht4
|
|
||||||
Aaron,RiverCascadeApple3
|
|
||||||
George,MeadowBreezePalace4
|
|
||||||
Carl,RadianceMirageQuasar2
|
|
||||||
Kenneth,IcebergPlanetHorizon8
|
|
||||||
Daniel,BreezeXylophoneGalaxy5
|
|
||||||
Ronald,PhoenixThunderZephyr2
|
|
||||||
Benjamin,NatureVolcanoNebula8
|
|
||||||
Joe,UnicornSapphireHorizon1
|
|
||||||
Larry,IslandZebraApple6
|
|
||||||
Zachary,SapphireUnicornJasmine0
|
|
||||||
Willie,UmbrellaVictoryHorizon8
|
|
||||||
Anthony,QueenZebraNebula9
|
|
||||||
Michael,TigerMountainNightfall8
|
|
||||||
Vincent,InfinityHorizonQuicksilver8
|
|
||||||
Roger,WinterXylophonePalace8
|
|
||||||
Kyle,IcebergDolphinDragon9
|
|
||||||
Henry,HarmonyKnightPalace7
|
|
||||||
Eugene,JourneyThunderPalace0
|
|
||||||
Billy,ThunderThunderQuicksilver9
|
|
||||||
Peter,OrchardJasmineVictory4
|
|
||||||
Christopher,QueenThunderAutumn5
|
|
||||||
Adam,SummerUnicornThunder7
|
|
||||||
Nathan,SerenityOrchardThunder2
|
|
||||||
Edward,MeadowGalaxyYellow6
|
|
||||||
Eric,DolphinNebulaYacht8
|
|
||||||
Brian,CastleFlowerGlacier4
|
|
||||||
Alexander,ForestSapphireZebra4
|
|
||||||
Andrew,GalaxyLemonApple0
|
|
||||||
Brandon,HarmonyTigerHarmony2
|
|
||||||
Russell,CherryZebraQuicksilver8
|
|
||||||
Jack,OrchardZephyrSapphire8
|
|
||||||
Jose,BananaJungleSerenity8
|
|
||||||
Jacob,KaleidoscopeEmeraldJasmine5
|
|
||||||
Dennis,KnightFlowerRainbow2
|
|
||||||
Donald,WhisperQuicksilverCastle1
|
|
||||||
William,ApplePalaceSummer6
|
|
||||||
Patrick,CastleInfinityPhoenix9
|
|
||||||
Timothy,YellowEagleSummer0
|
|
@@ -83,12 +83,12 @@ require('template/header.phtml')
|
|||||||
|
|
||||||
// Validate authentication with server first
|
// Validate authentication with server first
|
||||||
let isAdmin = false;
|
let isAdmin = false;
|
||||||
if (simpleAuth.isAuthenticated()) {
|
if (auth.isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
// This will validate the token with the server and handle refresh if needed
|
// This will validate the token with the server and handle refresh if needed
|
||||||
const isValid = await simpleAuth.validateOnLoad();
|
const isValid = await auth.validateOnLoad();
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
isAdmin = simpleAuth.isAdmin();
|
isAdmin = auth.isAdmin();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error validating authentication:', error);
|
console.error('Error validating authentication:', error);
|
||||||
|
@@ -96,12 +96,12 @@
|
|||||||
createModal.addEventListener('show.bs.modal', async function(event) {
|
createModal.addEventListener('show.bs.modal', async function(event) {
|
||||||
// Validate authentication with server first
|
// Validate authentication with server first
|
||||||
let isAdmin = false;
|
let isAdmin = false;
|
||||||
if (simpleAuth.isAuthenticated()) {
|
if (auth.isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
// This will validate the token with the server and handle refresh if needed
|
// This will validate the token with the server and handle refresh if needed
|
||||||
const isValid = await simpleAuth.validateOnLoad();
|
const isValid = await auth.validateOnLoad();
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
isAdmin = simpleAuth.isAdmin();
|
isAdmin = auth.isAdmin();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error validating authentication:', error);
|
console.error('Error validating authentication:', error);
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
<!-- Application JavaScript -->
|
<!-- Application JavaScript -->
|
||||||
<!-- Note: simpleAuth.js is already included in the header -->
|
<!-- Note: auth.js is already included in the header -->
|
||||||
<!-- Note: facilityData.js is already included in the header -->
|
<!-- Note: facilityData.js is already included in the header -->
|
||||||
<script src="/public/js/comments.js"></script>
|
<script src="/public/js/comments.js"></script>
|
||||||
|
|
||||||
@@ -55,12 +55,12 @@
|
|||||||
|
|
||||||
// initialise CommentsManager
|
// initialise CommentsManager
|
||||||
CommentsManager.state.isDomReady = true;
|
CommentsManager.state.isDomReady = true;
|
||||||
if (window.simpleAuth) {
|
if (window.auth) {
|
||||||
CommentsManager.state.isAuthReady = true;
|
CommentsManager.state.isAuthReady = true;
|
||||||
CommentsManager.checkinitialise();
|
CommentsManager.checkinitialise();
|
||||||
} else {
|
} else {
|
||||||
window.addEventListener('simpleAuthReady', () => {
|
window.addEventListener('authReady', () => {
|
||||||
console.log('SimpleAuth is now ready');
|
console.log('auth is now ready');
|
||||||
CommentsManager.state.isAuthReady = true;
|
CommentsManager.state.isAuthReady = true;
|
||||||
CommentsManager.checkinitialise();
|
CommentsManager.checkinitialise();
|
||||||
});
|
});
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
|
|
||||||
if (loginForm) {
|
if (loginForm) {
|
||||||
// Show CAPTCHA if needed
|
// Show CAPTCHA if needed
|
||||||
if (simpleAuth.needsCaptcha() && captchaContainer) {
|
if (auth.needsCaptcha() && captchaContainer) {
|
||||||
captchaContainer.style.display = 'flex';
|
captchaContainer.style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Attempt login
|
// Attempt login
|
||||||
const result = await simpleAuth.login({
|
const result = await auth.login({
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
captchaInput: captchaInput
|
captchaInput: captchaInput
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show CAPTCHA if needed
|
// Show CAPTCHA if needed
|
||||||
if (simpleAuth.needsCaptcha() && captchaContainer) {
|
if (auth.needsCaptcha() && captchaContainer) {
|
||||||
captchaContainer.style.display = 'flex';
|
captchaContainer.style.display = 'flex';
|
||||||
// Generate new CAPTCHA if needed
|
// Generate new CAPTCHA if needed
|
||||||
if (result.captcha) {
|
if (result.captcha) {
|
||||||
@@ -178,13 +178,13 @@
|
|||||||
if (logoutButton) {
|
if (logoutButton) {
|
||||||
logoutButton.addEventListener('click', async (e) => {
|
logoutButton.addEventListener('click', async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
await simpleAuth.logout();
|
await auth.logout();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate token if authenticated
|
// Validate token if authenticated
|
||||||
if (simpleAuth.isAuthenticated()) {
|
if (auth.isAuthenticated()) {
|
||||||
simpleAuth.validateToken().then(valid => {
|
auth.validateToken().then(valid => {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
if (!localStorage.getItem('validationAttempted')) {
|
if (!localStorage.getItem('validationAttempted')) {
|
||||||
localStorage.setItem('validationAttempted', 'true');
|
localStorage.setItem('validationAttempted', 'true');
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
<title>Ecobuddy - <?php echo $view->pageTitle; ?></title>
|
<title>Ecobuddy - <?php echo $view->pageTitle; ?></title>
|
||||||
|
|
||||||
<!-- Load simplified authentication helper -->
|
<!-- Load simplified authentication helper -->
|
||||||
<script src="/public/js/simpleAuth.js"></script>
|
<script src="/public/js/auth.js"></script>
|
||||||
|
|
||||||
<!-- Load API client -->
|
<!-- Load API client -->
|
||||||
<script src="/public/js/apiClient.js"></script>
|
<script src="/public/js/apiClient.js"></script>
|
||||||
@@ -66,11 +66,11 @@
|
|||||||
// Add client-side authentication check to update UI
|
// Add client-side authentication check to update UI
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
// Check if user is authenticated on the client side
|
// Check if user is authenticated on the client side
|
||||||
if (simpleAuth && simpleAuth.isAuthenticated()) {
|
if (auth && auth.isAuthenticated()) {
|
||||||
console.log('User is authenticated on client side');
|
console.log('User is authenticated on client side');
|
||||||
|
|
||||||
// Get user data
|
// Get user data
|
||||||
const user = simpleAuth.getUser();
|
const user = auth.getUser();
|
||||||
if (user) {
|
if (user) {
|
||||||
console.log('User data:', user);
|
console.log('User data:', user);
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
const logoutButton = document.getElementById('logoutButton');
|
const logoutButton = document.getElementById('logoutButton');
|
||||||
if (logoutButton) {
|
if (logoutButton) {
|
||||||
logoutButton.addEventListener('click', async function() {
|
logoutButton.addEventListener('click', async function() {
|
||||||
await simpleAuth.logout();
|
await auth.logout();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -187,10 +187,10 @@
|
|||||||
|
|
||||||
// Validate token with server first
|
// Validate token with server first
|
||||||
let isAuthenticated = false;
|
let isAuthenticated = false;
|
||||||
if (simpleAuth.isAuthenticated()) {
|
if (auth.isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
// This will validate the token with the server and handle refresh if needed
|
// This will validate the token with the server and handle refresh if needed
|
||||||
isAuthenticated = await simpleAuth.validateOnLoad();
|
isAuthenticated = await auth.validateOnLoad();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error validating authentication:', error);
|
console.error('Error validating authentication:', error);
|
||||||
isAuthenticated = false;
|
isAuthenticated = false;
|
||||||
@@ -207,8 +207,8 @@
|
|||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
// User is logged in - show user menu
|
// User is logged in - show user menu
|
||||||
const user = simpleAuth.getUser();
|
const user = auth.getUser();
|
||||||
const isAdmin = simpleAuth.isAdmin();
|
const isAdmin = auth.isAdmin();
|
||||||
|
|
||||||
authSection.innerHTML = `
|
authSection.innerHTML = `
|
||||||
<div class="user-menu">
|
<div class="user-menu">
|
||||||
@@ -233,7 +233,7 @@
|
|||||||
const logoutButton = authSection.querySelector('button[name="logoutButton"]');
|
const logoutButton = authSection.querySelector('button[name="logoutButton"]');
|
||||||
if (logoutButton) {
|
if (logoutButton) {
|
||||||
logoutButton.addEventListener('click', async () => {
|
logoutButton.addEventListener('click', async () => {
|
||||||
await simpleAuth.logout();
|
await auth.logout();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@
|
|||||||
// Update auth UI when the page loads
|
// Update auth UI when the page loads
|
||||||
document.addEventListener('DOMContentLoaded', updateAuthUI);
|
document.addEventListener('DOMContentLoaded', updateAuthUI);
|
||||||
|
|
||||||
// Also update when simpleAuth state changes
|
// Also update when auth state changes
|
||||||
window.addEventListener('storage', function(e) {
|
window.addEventListener('storage', function(e) {
|
||||||
if (e.key === 'token' || e.key === 'user') {
|
if (e.key === 'token' || e.key === 'user') {
|
||||||
updateAuthUI();
|
updateAuthUI();
|
||||||
@@ -341,7 +341,7 @@
|
|||||||
// Function to update CAPTCHA display
|
// Function to update CAPTCHA display
|
||||||
async function updateCaptcha() {
|
async function updateCaptcha() {
|
||||||
try {
|
try {
|
||||||
const captcha = await simpleAuth.generateCaptcha();
|
const captcha = await auth.generateCaptcha();
|
||||||
if (captchaDisplay) {
|
if (captchaDisplay) {
|
||||||
captchaDisplay.textContent = captcha;
|
captchaDisplay.textContent = captcha;
|
||||||
}
|
}
|
||||||
@@ -363,7 +363,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show/hide CAPTCHA based on login attempts
|
// Show/hide CAPTCHA based on login attempts
|
||||||
if (simpleAuth.needsCaptcha() && captchaContainer) {
|
if (auth.needsCaptcha() && captchaContainer) {
|
||||||
captchaContainer.style.display = 'block';
|
captchaContainer.style.display = 'block';
|
||||||
updateCaptcha();
|
updateCaptcha();
|
||||||
}
|
}
|
||||||
@@ -389,7 +389,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Attempt login
|
// Attempt login
|
||||||
const result = await simpleAuth.login({
|
const result = await auth.login({
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
captchaInput
|
captchaInput
|
||||||
@@ -448,7 +448,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hide modal if user is already authenticated
|
// Hide modal if user is already authenticated
|
||||||
if (simpleAuth.isAuthenticated() && loginModal) {
|
if (auth.isAuthenticated() && loginModal) {
|
||||||
const modalInstance = bootstrap.Modal.getInstance(loginModal);
|
const modalInstance = bootstrap.Modal.getInstance(loginModal);
|
||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
|
@@ -79,7 +79,7 @@
|
|||||||
// Function to update CAPTCHA display
|
// Function to update CAPTCHA display
|
||||||
async function updateCaptcha() {
|
async function updateCaptcha() {
|
||||||
try {
|
try {
|
||||||
const captcha = await simpleAuth.generateCaptcha();
|
const captcha = await auth.generateCaptcha();
|
||||||
captchaDisplay.textContent = captcha;
|
captchaDisplay.textContent = captcha;
|
||||||
document.getElementById('captchaCode').value = captcha;
|
document.getElementById('captchaCode').value = captcha;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show/hide CAPTCHA based on login attempts
|
// Show/hide CAPTCHA based on login attempts
|
||||||
if (simpleAuth.needsCaptcha()) {
|
if (auth.needsCaptcha()) {
|
||||||
captchaContainer.style.display = 'block';
|
captchaContainer.style.display = 'block';
|
||||||
updateCaptcha();
|
updateCaptcha();
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
const password = document.getElementById('password').value;
|
const password = document.getElementById('password').value;
|
||||||
const captchaInput = document.getElementById('captchaInput')?.value;
|
const captchaInput = document.getElementById('captchaInput')?.value;
|
||||||
|
|
||||||
const result = await simpleAuth.login({
|
const result = await auth.login({
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
captchaInput
|
captchaInput
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
* authentication and common request patterns.
|
* authentication and common request patterns.
|
||||||
*
|
*
|
||||||
* The client uses JWT tokens for authentication, which are automatically
|
* The client uses JWT tokens for authentication, which are automatically
|
||||||
* included in requests via the fetchAuth function provided by the simpleAuth service.
|
* included in requests via the fetchAuth function provided by the auth service.
|
||||||
*
|
*
|
||||||
* Similar to AuthService.php, great pain and countless tears. And learning woooo!!!!!!!!
|
* Similar to AuthService.php, great pain and countless tears. And learning woooo!!!!!!!!
|
||||||
*/
|
*/
|
||||||
@@ -14,25 +14,25 @@ class ApiClient {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* Initialises the API client and sets up the authenticated fetch function.
|
* Initialises the API client and sets up the authenticated fetch function.
|
||||||
* Relies on the simpleAuth service being available in the global scope.
|
* Relies on the auth service being available in the global scope.
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
// Ensure auth service is available
|
// Ensure auth service is available
|
||||||
if (!simpleAuth) {
|
if (!auth) {
|
||||||
console.error('Auth service not available');
|
console.error('Auth service not available');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the fetchAuth method from simpleAuth
|
// Use the fetchAuth method from auth
|
||||||
this.authFetch = async (url, options = {}) => {
|
this.authFetch = async (url, options = {}) => {
|
||||||
try {
|
try {
|
||||||
// For unauthenticated requests or when authentication is not required
|
// For unauthenticated requests or when authentication is not required
|
||||||
if (!options.requireAuth || !simpleAuth.isAuthenticated()) {
|
if (!options.requireAuth || !auth.isAuthenticated()) {
|
||||||
return fetch(url, options);
|
return fetch(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For authenticated requests
|
// For authenticated requests
|
||||||
delete options.requireAuth; // Remove the custom property
|
delete options.requireAuth; // Remove the custom property
|
||||||
return simpleAuth.fetchAuth(url, options);
|
return auth.fetchAuth(url, options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in authFetch:', error);
|
console.error('Error in authFetch:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
* I admit JWT is unnecessary, but I did it anyway because it was interesting
|
* I admit JWT is unnecessary, but I did it anyway because it was interesting
|
||||||
* and I wanted to try it out.
|
* and I wanted to try it out.
|
||||||
*/
|
*/
|
||||||
class SimpleAuth {
|
class Auth {
|
||||||
/**
|
/**
|
||||||
* initialise the authentication helper
|
* initialise the authentication helper
|
||||||
*/
|
*/
|
||||||
@@ -360,13 +360,10 @@ class SimpleAuth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a global instance and expose it
|
// Create a global instance and expose it
|
||||||
window.simpleAuth = new SimpleAuth();
|
window.auth = new Auth();
|
||||||
|
|
||||||
// Also create an alias for backward compatibility
|
// Log that auth is ready
|
||||||
window.auth = window.simpleAuth;
|
console.log('auth is ready and exposed to window');
|
||||||
|
|
||||||
// Log that simpleAuth is ready
|
|
||||||
console.log('SimpleAuth is ready and exposed to window');
|
|
||||||
|
|
||||||
// Dispatch a custom event to notify other scripts
|
// Dispatch a custom event to notify other scripts
|
||||||
window.dispatchEvent(new Event('simpleAuthReady'));
|
window.dispatchEvent(new Event('authReady'));
|
@@ -7,7 +7,7 @@ const CommentsManager = {
|
|||||||
// Initialization states
|
// Initialization states
|
||||||
state: {
|
state: {
|
||||||
isInitializing: false,
|
isInitializing: false,
|
||||||
isinitialised: false,
|
isInitialised: false,
|
||||||
isDomReady: false,
|
isDomReady: false,
|
||||||
isAuthReady: false
|
isAuthReady: false
|
||||||
},
|
},
|
||||||
@@ -16,7 +16,7 @@ const CommentsManager = {
|
|||||||
* initialise status functionality
|
* initialise status functionality
|
||||||
*/
|
*/
|
||||||
initialise() {
|
initialise() {
|
||||||
if (this.state.isinitialised) return;
|
if (this.state.isInitialised) return;
|
||||||
|
|
||||||
console.log('Initializing comments...');
|
console.log('Initializing comments...');
|
||||||
|
|
||||||
@@ -28,10 +28,10 @@ const CommentsManager = {
|
|||||||
|
|
||||||
console.log('Comments initialised with auth state:', {
|
console.log('Comments initialised with auth state:', {
|
||||||
isAuthenticated: this.isAuthenticated(),
|
isAuthenticated: this.isAuthenticated(),
|
||||||
user: window.simpleAuth.getUser()
|
user: window.auth.getUser()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.state.isinitialised = true;
|
this.state.isInitialised = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +49,7 @@ const CommentsManager = {
|
|||||||
* Check if user is authenticated
|
* Check if user is authenticated
|
||||||
*/
|
*/
|
||||||
isAuthenticated() {
|
isAuthenticated() {
|
||||||
return window.simpleAuth && window.simpleAuth.isAuthenticated();
|
return window.auth && window.auth.isAuthenticated();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,8 +253,8 @@ const CommentsManager = {
|
|||||||
* Creates a comment form dynamically for authenticated users
|
* Creates a comment form dynamically for authenticated users
|
||||||
*/
|
*/
|
||||||
createCommentFormForAuthenticatedUser(facilityId) {
|
createCommentFormForAuthenticatedUser(facilityId) {
|
||||||
// First check if simpleAuth is available
|
// First check if auth is available
|
||||||
if (!window.simpleAuth) {
|
if (!window.auth) {
|
||||||
return `
|
return `
|
||||||
<div class="alert alert-warning mb-0">
|
<div class="alert alert-warning mb-0">
|
||||||
<i class="bi bi-hourglass-split me-2"></i>
|
<i class="bi bi-hourglass-split me-2"></i>
|
||||||
@@ -265,9 +265,9 @@ const CommentsManager = {
|
|||||||
|
|
||||||
// Validate authentication state
|
// Validate authentication state
|
||||||
try {
|
try {
|
||||||
const token = window.simpleAuth.getToken();
|
const token = window.auth.getToken();
|
||||||
const user = window.simpleAuth.getUser();
|
const user = window.auth.getUser();
|
||||||
const isAuthenticated = window.simpleAuth.isAuthenticated();
|
const isAuthenticated = window.auth.isAuthenticated();
|
||||||
|
|
||||||
if (!isAuthenticated || !token || !user) {
|
if (!isAuthenticated || !token || !user) {
|
||||||
return `
|
return `
|
||||||
@@ -483,14 +483,14 @@ const CommentsManager = {
|
|||||||
* Checks if the current user is an admin
|
* Checks if the current user is an admin
|
||||||
*/
|
*/
|
||||||
isAdmin() {
|
isAdmin() {
|
||||||
return window.simpleAuth && window.simpleAuth.isAdmin();
|
return window.auth && window.auth.isAdmin();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given username matches the current user
|
* Checks if the given username matches the current user
|
||||||
*/
|
*/
|
||||||
isCurrentUser(username) {
|
isCurrentUser(username) {
|
||||||
const user = window.simpleAuth && window.simpleAuth.getUser();
|
const user = window.auth && window.auth.getUser();
|
||||||
return user && user.username === username;
|
return user && user.username === username;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -522,21 +522,21 @@ if (document.readyState === 'loading') {
|
|||||||
CommentsManager.checkinitialise();
|
CommentsManager.checkinitialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for simpleAuth ready
|
// Listen for auth ready
|
||||||
if (window.simpleAuth) {
|
if (window.auth) {
|
||||||
CommentsManager.state.isAuthReady = true;
|
CommentsManager.state.isAuthReady = true;
|
||||||
CommentsManager.checkinitialise();
|
CommentsManager.checkinitialise();
|
||||||
} else {
|
} else {
|
||||||
window.addEventListener('simpleAuthReady', () => {
|
window.addEventListener('authReady', () => {
|
||||||
console.log('SimpleAuth is now ready');
|
console.log('auth is now ready');
|
||||||
CommentsManager.state.isAuthReady = true;
|
CommentsManager.state.isAuthReady = true;
|
||||||
CommentsManager.checkinitialise();
|
CommentsManager.checkinitialise();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fallback timeout in case the event doesn't fire
|
// Fallback timeout in case the event doesn't fire
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!CommentsManager.state.isAuthReady && window.simpleAuth) {
|
if (!CommentsManager.state.isAuthReady && window.auth) {
|
||||||
console.log('SimpleAuth found via timeout check');
|
console.log('auth found via timeout check');
|
||||||
CommentsManager.state.isAuthReady = true;
|
CommentsManager.state.isAuthReady = true;
|
||||||
CommentsManager.checkinitialise();
|
CommentsManager.checkinitialise();
|
||||||
}
|
}
|
||||||
|
@@ -272,8 +272,8 @@ function isAdmin() {
|
|||||||
console.log('Checking admin status...');
|
console.log('Checking admin status...');
|
||||||
|
|
||||||
// Check if auth service is available and has user data
|
// Check if auth service is available and has user data
|
||||||
if (simpleAuth && simpleAuth.getUser()) {
|
if (auth && auth.getUser()) {
|
||||||
const authUser = simpleAuth.getUser();
|
const authUser = auth.getUser();
|
||||||
console.log('Auth service user data:', authUser);
|
console.log('Auth service user data:', authUser);
|
||||||
console.log('Auth service accessLevel:', authUser.accessLevel);
|
console.log('Auth service accessLevel:', authUser.accessLevel);
|
||||||
console.log('Auth service isAdmin check:', authUser.accessLevel === 1 || authUser.accessLevel === 0);
|
console.log('Auth service isAdmin check:', authUser.accessLevel === 1 || authUser.accessLevel === 0);
|
||||||
@@ -302,8 +302,8 @@ function isAdmin() {
|
|||||||
*/
|
*/
|
||||||
function isAuthenticated() {
|
function isAuthenticated() {
|
||||||
// Check if auth service is available
|
// Check if auth service is available
|
||||||
if (simpleAuth) {
|
if (auth) {
|
||||||
return simpleAuth.isAuthenticated();
|
return auth.isAuthenticated();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to localStorage
|
// Fallback to localStorage
|
||||||
@@ -497,8 +497,8 @@ function setupFormHandlers() {
|
|||||||
// Set the action to 'create'
|
// Set the action to 'create'
|
||||||
formData.set('action', 'create');
|
formData.set('action', 'create');
|
||||||
try {
|
try {
|
||||||
// Use simpleAuth.fetchAuth for authenticated requests
|
// Use auth.fetchAuth for authenticated requests
|
||||||
const response = await simpleAuth.fetchAuth('/facilitycontroller.php', {
|
const response = await auth.fetchAuth('/facilitycontroller.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
@@ -605,8 +605,8 @@ function setupFormHandlers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use simpleAuth.fetchAuth for authenticated requests
|
// Use auth.fetchAuth for authenticated requests
|
||||||
const response = await simpleAuth.fetchAuth('/facilitycontroller.php', {
|
const response = await auth.fetchAuth('/facilitycontroller.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: serverFormData
|
body: serverFormData
|
||||||
});
|
});
|
||||||
@@ -694,19 +694,19 @@ function setupFormHandlers() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if token is valid
|
// Check if token is valid
|
||||||
if (!simpleAuth) {
|
if (!auth) {
|
||||||
throw new Error('Auth service not available');
|
throw new Error('Auth service not available');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate token with server before proceeding
|
// Validate token with server before proceeding
|
||||||
console.log('Validating token with server...');
|
console.log('Validating token with server...');
|
||||||
const isValid = await simpleAuth.validateToken();
|
const isValid = await auth.validateToken();
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
throw new Error('Authentication token is invalid or expired');
|
throw new Error('Authentication token is invalid or expired');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get token after validation to ensure it's fresh
|
// Get token after validation to ensure it's fresh
|
||||||
const token = simpleAuth.getToken();
|
const token = auth.getToken();
|
||||||
console.log('Using token for delete request:', token);
|
console.log('Using token for delete request:', token);
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
@@ -714,16 +714,16 @@ function setupFormHandlers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode token to check payload
|
// Decode token to check payload
|
||||||
if (simpleAuth.parseJwt) {
|
if (auth.parseJwt) {
|
||||||
const payload = simpleAuth.parseJwt(token);
|
const payload = auth.parseJwt(token);
|
||||||
console.log('Token payload:', payload);
|
console.log('Token payload:', payload);
|
||||||
console.log('Access level:', payload.accessLevel);
|
console.log('Access level:', payload.accessLevel);
|
||||||
console.log('Is admin check:', payload.accessLevel === 0 || payload.accessLevel === 1);
|
console.log('Is admin check:', payload.accessLevel === 0 || payload.accessLevel === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use simpleAuth.fetchAuth for authenticated requests
|
// Use auth.fetchAuth for authenticated requests
|
||||||
console.log('Sending delete request to server...');
|
console.log('Sending delete request to server...');
|
||||||
const response = await simpleAuth.fetchAuth('/facilitycontroller.php', {
|
const response = await auth.fetchAuth('/facilitycontroller.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
|
@@ -92,84 +92,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
setupHeaderSearchHandler();
|
setupHeaderSearchHandler();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Get postcode from coordinates using postcodes.io API
|
|
||||||
* @param {number} lat - Latitude
|
|
||||||
* @param {number} lng - Longitude
|
|
||||||
* @returns {Promise<string>} The postcode
|
|
||||||
*/
|
|
||||||
async function getPostcodeFromCoordinates(lat, lng) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`https://api.postcodes.io/postcodes?lon=${lng}&lat=${lat}`);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Could not find postcode for coordinates');
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
if (data.status === 200 && data.result && data.result.length > 0) {
|
|
||||||
return data.result[0].postcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('No postcode found for coordinates');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error getting postcode from coordinates:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle geolocation success
|
|
||||||
* @param {GeolocationPosition} position - The position object
|
|
||||||
*/
|
|
||||||
async function handleGeolocationSuccess(position) {
|
|
||||||
try {
|
|
||||||
const { latitude, longitude } = position.coords;
|
|
||||||
|
|
||||||
// Get postcode from coordinates
|
|
||||||
const postcode = await getPostcodeFromCoordinates(latitude, longitude);
|
|
||||||
|
|
||||||
// Update the postcode input
|
|
||||||
const postcodeInput = document.getElementById('postcode');
|
|
||||||
if (postcodeInput) {
|
|
||||||
postcodeInput.value = postcode;
|
|
||||||
|
|
||||||
// Submit the form to update the map
|
|
||||||
const postcodeForm = document.getElementById('postcodeForm');
|
|
||||||
if (postcodeForm) {
|
|
||||||
postcodeForm.dispatchEvent(new Event('submit'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error processing geolocation:', error);
|
|
||||||
alert('Error getting your location: ' + error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle geolocation error
|
|
||||||
* @param {GeolocationPositionError} error - The error object
|
|
||||||
*/
|
|
||||||
function handleGeolocationError(error) {
|
|
||||||
console.error('Geolocation error:', error);
|
|
||||||
let message = 'Error getting your location: ';
|
|
||||||
|
|
||||||
switch(error.code) {
|
|
||||||
case error.PERMISSION_DENIED:
|
|
||||||
message += 'Please enable location access in your browser settings.';
|
|
||||||
break;
|
|
||||||
case error.POSITION_UNAVAILABLE:
|
|
||||||
message += 'Location information is unavailable.';
|
|
||||||
break;
|
|
||||||
case error.TIMEOUT:
|
|
||||||
message += 'Location request timed out.';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
message += 'An unknown error occurred.';
|
|
||||||
}
|
|
||||||
|
|
||||||
alert(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up form handlers for postcode and radius inputs
|
* Set up form handlers for postcode and radius inputs
|
||||||
*/
|
*/
|
||||||
@@ -245,11 +167,13 @@ function setupFormHandlers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (radiusSelect) {
|
if (radiusSelect) {
|
||||||
radiusSelect.addEventListener('change', function() {
|
radiusSelect.addEventListener('change', async function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const postcode = document.getElementById('postcode').value;
|
||||||
|
const coords = await getPostcodeCoordinates(postcode);
|
||||||
const radius = parseFloat(this.value);
|
const radius = parseFloat(this.value);
|
||||||
if (currentPostcode) {
|
updateMapLocation(coords, radius);
|
||||||
updateMapLocation(null, radius); // null coords means use existing center
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -402,7 +326,7 @@ function toRad(degrees) {
|
|||||||
* @returns {string} HTML content for popup
|
* @returns {string} HTML content for popup
|
||||||
*/
|
*/
|
||||||
function createPopupContent(facility) {
|
function createPopupContent(facility) {
|
||||||
const isAuthenticated = window.simpleAuth && window.simpleAuth.isAuthenticated();
|
const isAuthenticated = window.auth && window.auth.isAuthenticated();
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="facility-popup">
|
<div class="facility-popup">
|
||||||
@@ -498,7 +422,7 @@ async function handleCommentSubmit(event, facilityId) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Check authentication
|
// Check authentication
|
||||||
if (!window.simpleAuth || !window.simpleAuth.isAuthenticated()) {
|
if (!window.auth || !window.auth.isAuthenticated()) {
|
||||||
alert('You must be logged in to add comments');
|
alert('You must be logged in to add comments');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user