Remove semicolons
This commit is contained in:
parent
0f71f80446
commit
28911d117e
@ -2,32 +2,32 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Initialize the app
|
||||
initializeApp();
|
||||
initializeApp()
|
||||
|
||||
// Authentication form handler
|
||||
const authForm = document.getElementById('authenticationForm');
|
||||
const authForm = document.getElementById('authenticationForm')
|
||||
if (authForm) {
|
||||
const authSubmitBtn = authForm.querySelector('button[type="submit"]');
|
||||
const authSubmitBtn = authForm.querySelector('button[type="submit"]')
|
||||
|
||||
authForm.addEventListener('submit', async (ev) => {
|
||||
ev.preventDefault();
|
||||
authSubmitBtn.disabled = true;
|
||||
clearStatus('loginStatus');
|
||||
ev.preventDefault()
|
||||
authSubmitBtn.disabled = true
|
||||
clearStatus('loginStatus')
|
||||
|
||||
try {
|
||||
showStatus('loginStatus', 'Starting authentication...', 'info');
|
||||
await authenticate();
|
||||
showStatus('loginStatus', 'Authentication successful!', 'success');
|
||||
showStatus('loginStatus', 'Starting authentication...', 'info')
|
||||
await authenticate()
|
||||
showStatus('loginStatus', 'Authentication successful!', 'success')
|
||||
|
||||
// Navigate to profile
|
||||
setTimeout(() => {
|
||||
window.location.href = '/auth/profile';
|
||||
}, 1000);
|
||||
window.location.href = '/auth/profile'
|
||||
}, 1000)
|
||||
} catch (err) {
|
||||
showStatus('loginStatus', `Authentication failed: ${err.message}`, 'error');
|
||||
showStatus('loginStatus', `Authentication failed: ${err.message}`, 'error')
|
||||
} finally {
|
||||
authSubmitBtn.disabled = false;
|
||||
authSubmitBtn.disabled = false
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
||||
|
@ -2,68 +2,68 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Initialize the app
|
||||
initializeApp();
|
||||
initializeApp()
|
||||
|
||||
// Setup dialog event handlers
|
||||
setupDialogHandlers();
|
||||
});
|
||||
setupDialogHandlers()
|
||||
})
|
||||
|
||||
// Setup dialog event handlers
|
||||
function setupDialogHandlers() {
|
||||
// Close dialog when clicking outside
|
||||
const dialog = document.getElementById('deviceLinkDialog');
|
||||
const dialog = document.getElementById('deviceLinkDialog')
|
||||
if (dialog) {
|
||||
dialog.addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeDeviceLinkDialog();
|
||||
closeDeviceLinkDialog()
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// Close dialog when pressing Escape key
|
||||
document.addEventListener('keydown', function(e) {
|
||||
const dialog = document.getElementById('deviceLinkDialog');
|
||||
const dialog = document.getElementById('deviceLinkDialog')
|
||||
if (e.key === 'Escape' && dialog && dialog.open) {
|
||||
closeDeviceLinkDialog();
|
||||
closeDeviceLinkDialog()
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// Open device link dialog
|
||||
function openDeviceLinkDialog() {
|
||||
const dialog = document.getElementById('deviceLinkDialog');
|
||||
const container = document.querySelector('.container');
|
||||
const body = document.body;
|
||||
const dialog = document.getElementById('deviceLinkDialog')
|
||||
const container = document.querySelector('.container')
|
||||
const body = document.body
|
||||
|
||||
if (dialog && container && body) {
|
||||
// Add blur and disable effects
|
||||
container.classList.add('dialog-open');
|
||||
body.classList.add('dialog-open');
|
||||
container.classList.add('dialog-open')
|
||||
body.classList.add('dialog-open')
|
||||
|
||||
dialog.showModal();
|
||||
generateDeviceLink();
|
||||
dialog.showModal()
|
||||
generateDeviceLink()
|
||||
}
|
||||
}
|
||||
|
||||
// Close device link dialog
|
||||
function closeDeviceLinkDialog() {
|
||||
const dialog = document.getElementById('deviceLinkDialog');
|
||||
const container = document.querySelector('.container');
|
||||
const body = document.body;
|
||||
const dialog = document.getElementById('deviceLinkDialog')
|
||||
const container = document.querySelector('.container')
|
||||
const body = document.body
|
||||
|
||||
if (dialog && container && body) {
|
||||
// Remove blur and disable effects
|
||||
container.classList.remove('dialog-open');
|
||||
body.classList.remove('dialog-open');
|
||||
container.classList.remove('dialog-open')
|
||||
body.classList.remove('dialog-open')
|
||||
|
||||
dialog.close();
|
||||
dialog.close()
|
||||
}
|
||||
}
|
||||
|
||||
// Generate device link function
|
||||
function generateDeviceLink() {
|
||||
clearStatus('deviceAdditionStatus');
|
||||
showStatus('deviceAdditionStatus', 'Generating device link...', 'info');
|
||||
clearStatus('deviceAdditionStatus')
|
||||
showStatus('deviceAdditionStatus', 'Generating device link...', 'info')
|
||||
|
||||
fetch('/api/create-device-link', {
|
||||
method: 'POST',
|
||||
@ -71,45 +71,41 @@ function generateDeviceLink() {
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.error) throw new Error(result.error);
|
||||
if (result.error) throw new Error(result.error)
|
||||
|
||||
// Update UI with the link
|
||||
const deviceLinkText = document.getElementById('deviceLinkText');
|
||||
const deviceToken = document.getElementById('deviceToken');
|
||||
const deviceLinkText = document.getElementById('deviceLinkText')
|
||||
const deviceToken = document.getElementById('deviceToken')
|
||||
|
||||
if (deviceLinkText) {
|
||||
deviceLinkText.textContent = result.addition_link;
|
||||
deviceLinkText.textContent = result.addition_link
|
||||
}
|
||||
|
||||
if (deviceToken) {
|
||||
deviceToken.textContent = result.token;
|
||||
deviceToken.textContent = result.token
|
||||
}
|
||||
|
||||
// Store link globally for copy function
|
||||
window.currentDeviceLink = result.addition_link;
|
||||
window.currentDeviceLink = result.addition_link
|
||||
|
||||
// Generate QR code
|
||||
const qrCodeEl = document.getElementById('qrCode');
|
||||
const qrCodeEl = document.getElementById('qrCode')
|
||||
if (qrCodeEl && typeof QRCode !== 'undefined') {
|
||||
qrCodeEl.innerHTML = '';
|
||||
qrCodeEl.innerHTML = ''
|
||||
new QRCode(qrCodeEl, {
|
||||
text: result.addition_link,
|
||||
width: 200,
|
||||
height: 200,
|
||||
colorDark: '#000000',
|
||||
colorLight: '#ffffff',
|
||||
correctLevel: QRCode.CorrectLevel.M
|
||||
});
|
||||
colorLight: '#ffffff'
|
||||
})
|
||||
}
|
||||
|
||||
showStatus('deviceAdditionStatus', 'Device link generated successfully!', 'success');
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error generating device link:', error);
|
||||
showStatus('deviceAdditionStatus', `Failed to generate device link: ${error.message}`, 'error');
|
||||
});
|
||||
showStatus('deviceAdditionStatus', `Failed to generate device link: ${error.message}`, 'error')
|
||||
})
|
||||
}
|
||||
|
||||
// Make functions available globally for onclick handlers
|
||||
window.openDeviceLinkDialog = openDeviceLinkDialog;
|
||||
window.closeDeviceLinkDialog = closeDeviceLinkDialog;
|
||||
window.openDeviceLinkDialog = openDeviceLinkDialog
|
||||
window.closeDeviceLinkDialog = closeDeviceLinkDialog
|
||||
|
@ -2,34 +2,34 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Initialize the app
|
||||
initializeApp();
|
||||
initializeApp()
|
||||
|
||||
// Registration form handler
|
||||
const regForm = document.getElementById('registrationForm');
|
||||
const regForm = document.getElementById('registrationForm')
|
||||
if (regForm) {
|
||||
const regSubmitBtn = regForm.querySelector('button[type="submit"]');
|
||||
const regSubmitBtn = regForm.querySelector('button[type="submit"]')
|
||||
|
||||
regForm.addEventListener('submit', async (ev) => {
|
||||
ev.preventDefault();
|
||||
regSubmitBtn.disabled = true;
|
||||
clearStatus('registerStatus');
|
||||
ev.preventDefault()
|
||||
regSubmitBtn.disabled = true
|
||||
clearStatus('registerStatus')
|
||||
|
||||
const user_name = (new FormData(regForm)).get('username');
|
||||
const user_name = (new FormData(regForm)).get('username')
|
||||
|
||||
try {
|
||||
showStatus('registerStatus', 'Starting registration...', 'info');
|
||||
await register(user_name);
|
||||
showStatus('registerStatus', `Registration successful for ${user_name}!`, 'success');
|
||||
showStatus('registerStatus', 'Starting registration...', 'info')
|
||||
await register(user_name)
|
||||
showStatus('registerStatus', `Registration successful for ${user_name}!`, 'success')
|
||||
|
||||
// Auto-login after successful registration
|
||||
setTimeout(() => {
|
||||
window.location.href = '/auth/profile';
|
||||
}, 1500);
|
||||
window.location.href = '/auth/profile'
|
||||
}, 1500)
|
||||
} catch (err) {
|
||||
showStatus('registerStatus', `Registration failed: ${err.message}`, 'error');
|
||||
showStatus('registerStatus', `Registration failed: ${err.message}`, 'error')
|
||||
} finally {
|
||||
regSubmitBtn.disabled = false;
|
||||
regSubmitBtn.disabled = false
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
||||
|
@ -2,57 +2,57 @@
|
||||
|
||||
// Initialize the app based on current page
|
||||
function initializeApp() {
|
||||
checkExistingSession();
|
||||
checkExistingSession()
|
||||
}
|
||||
|
||||
// Show status message
|
||||
function showStatus(elementId, message, type = 'info') {
|
||||
const statusEl = document.getElementById(elementId);
|
||||
const statusEl = document.getElementById(elementId)
|
||||
if (statusEl) {
|
||||
statusEl.innerHTML = `<div class="status ${type}">${message}</div>`;
|
||||
statusEl.innerHTML = `<div class="status ${type}">${message}</div>`
|
||||
}
|
||||
}
|
||||
|
||||
// Clear status message
|
||||
function clearStatus(elementId) {
|
||||
const statusEl = document.getElementById(elementId);
|
||||
const statusEl = document.getElementById(elementId)
|
||||
if (statusEl) {
|
||||
statusEl.innerHTML = '';
|
||||
statusEl.innerHTML = ''
|
||||
}
|
||||
}
|
||||
|
||||
// Check if user is already logged in on page load
|
||||
async function checkExistingSession() {
|
||||
const isLoggedIn = await validateStoredToken();
|
||||
const path = window.location.pathname;
|
||||
const isLoggedIn = await validateStoredToken()
|
||||
const path = window.location.pathname
|
||||
|
||||
// Protected routes that require authentication
|
||||
const protectedRoutes = ['/auth/profile'];
|
||||
const protectedRoutes = ['/auth/profile']
|
||||
|
||||
if (isLoggedIn) {
|
||||
// User is logged in
|
||||
if (path === '/auth/login' || path === '/auth/register' || path === '/') {
|
||||
// Redirect to profile if accessing login/register pages while logged in
|
||||
window.location.href = '/auth/profile';
|
||||
window.location.href = '/auth/profile'
|
||||
} else if (path === '/auth/add-device') {
|
||||
// Redirect old add-device route to profile
|
||||
window.location.href = '/auth/profile';
|
||||
window.location.href = '/auth/profile'
|
||||
} else if (protectedRoutes.includes(path)) {
|
||||
// Stay on current protected page and load user data
|
||||
if (path === '/auth/profile') {
|
||||
loadUserInfo().then(() => {
|
||||
updateUserInfo();
|
||||
loadCredentials();
|
||||
updateUserInfo()
|
||||
loadCredentials()
|
||||
}).catch(error => {
|
||||
showStatus('profileStatus', `Failed to load user info: ${error.message}`, 'error');
|
||||
});
|
||||
showStatus('profileStatus', `Failed to load user info: ${error.message}`, 'error')
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// User is not logged in
|
||||
if (protectedRoutes.includes(path) || path === '/auth/add-device') {
|
||||
// Redirect to login if accessing protected pages without authentication
|
||||
window.location.href = '/auth/login';
|
||||
window.location.href = '/auth/login'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,12 +63,12 @@ async function validateStoredToken() {
|
||||
const response = await fetch('/api/validate-token', {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
});
|
||||
})
|
||||
|
||||
const result = await response.json();
|
||||
return result.status === 'success';
|
||||
const result = await response.json()
|
||||
return result.status === 'success'
|
||||
} catch (error) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,28 +76,28 @@ async function validateStoredToken() {
|
||||
async function copyDeviceLink() {
|
||||
try {
|
||||
if (window.currentDeviceLink) {
|
||||
await navigator.clipboard.writeText(window.currentDeviceLink);
|
||||
await navigator.clipboard.writeText(window.currentDeviceLink)
|
||||
|
||||
const copyButton = document.querySelector('.copy-button');
|
||||
const copyButton = document.querySelector('.copy-button')
|
||||
if (copyButton) {
|
||||
const originalText = copyButton.textContent;
|
||||
copyButton.textContent = 'Copied!';
|
||||
copyButton.style.background = '#28a745';
|
||||
const originalText = copyButton.textContent
|
||||
copyButton.textContent = 'Copied!'
|
||||
copyButton.style.background = '#28a745'
|
||||
|
||||
setTimeout(() => {
|
||||
copyButton.textContent = originalText;
|
||||
copyButton.style.background = '#28a745';
|
||||
}, 2000);
|
||||
copyButton.textContent = originalText
|
||||
copyButton.style.background = '#28a745'
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to copy link:', error);
|
||||
const linkText = document.getElementById('deviceLinkText');
|
||||
console.error('Failed to copy link:', error)
|
||||
const linkText = document.getElementById('deviceLinkText')
|
||||
if (linkText) {
|
||||
const range = document.createRange();
|
||||
range.selectNode(linkText);
|
||||
window.getSelection().removeAllRanges();
|
||||
window.getSelection().addRange(range);
|
||||
const range = document.createRange()
|
||||
range.selectNode(linkText)
|
||||
window.getSelection().removeAllRanges()
|
||||
window.getSelection().addRange(range)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user