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