From 5b0b30d69c5794178f8bcdaa0b58642cb9bf8592 Mon Sep 17 00:00:00 2001 From: Tanishq Dubey Date: Sun, 8 Dec 2024 18:03:44 -0500 Subject: [PATCH] Fix CSP Error Getting rid of inline onclick calls and registering the handler in the primary script ensure securty (XSS). --- templates/admin.html | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/templates/admin.html b/templates/admin.html index 739ddc0..2feb59d 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -203,8 +203,8 @@ {{ photo.iso }} {{ photo.width }}x{{ photo.height }} - - + + {% endfor %} @@ -241,8 +241,11 @@
- - + +
+ Profile + +
@@ -335,11 +338,38 @@ } } + document.getElementById('delete-btn').addEventListener('click', deletePhoto); + document.getElementById('save-btn').addEventListener('click', saveChanges); + + document.getElementById('profile_image_upload').addEventListener('change', async (e) => { + const file = e.target.files[0]; + if (!file) return; + + const formData = new FormData(); + formData.append('profile_image', file); + + try { + const response = await fetch('/admin/upload_profile', { + method: 'POST', + body: formData + }); + + const result = await response.json(); + if (result.success) { + document.getElementById('profile-preview').src = '/static/profile.jpeg?' + new Date().getTime(); + } else { + alert('Error uploading profile image: ' + result.error); + } + } catch (error) { + alert('Error uploading profile image: ' + error); + } + }); + document.getElementById('configForm').addEventListener('submit', async (e) => { e.preventDefault(); const formData = {}; - const inputs = e.target.querySelectorAll('input, textarea'); + const inputs = e.target.querySelectorAll('input:not([type="file"]), textarea'); inputs.forEach(input => { formData[input.name] = input.value;