refactor: use .env file for admin password instead of hardcoded 1234
This commit is contained in:
@@ -202,7 +202,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const response = await fetch('feedback_backend.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'delete', id: id, secret: '1234' })
|
||||
body: JSON.stringify({ action: 'delete', id: id, secret: sessionStorage.getItem('schnappix_admin_secret') || '' })
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
@@ -240,7 +240,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const response = await fetch('feedback_backend.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'answer', id: id, answer: answer, secret: '1234' })
|
||||
body: JSON.stringify({ action: 'answer', id: id, answer: answer, secret: sessionStorage.getItem('schnappix_admin_secret') || '' })
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
@@ -424,26 +424,37 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
if (adminLoginForm) {
|
||||
adminLoginForm.addEventListener('submit', (e) => {
|
||||
adminLoginForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const password = adminPasswordInput.value;
|
||||
// Admin password matching the default app settings: "1234"
|
||||
if (password === '1234') {
|
||||
isAdmin = true;
|
||||
sessionStorage.setItem('schnappix_is_admin', 'true');
|
||||
adminPasswordInput.value = '';
|
||||
adminLoginError.style.display = 'none';
|
||||
|
||||
try {
|
||||
const response = await fetch('feedback_backend.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'verify_password', secret: password })
|
||||
});
|
||||
|
||||
// Switch Modals
|
||||
adminLoginModal.classList.remove('open');
|
||||
adminPanelModal.classList.add('open');
|
||||
|
||||
// Re-render to show trash cans
|
||||
renderFeedback(getActiveFilter());
|
||||
} else {
|
||||
if (response.ok) {
|
||||
isAdmin = true;
|
||||
sessionStorage.setItem('schnappix_is_admin', 'true');
|
||||
sessionStorage.setItem('schnappix_admin_secret', password);
|
||||
adminPasswordInput.value = '';
|
||||
adminLoginError.style.display = 'none';
|
||||
|
||||
// Switch Modals
|
||||
adminLoginModal.classList.remove('open');
|
||||
adminPanelModal.classList.add('open');
|
||||
|
||||
// Re-render to show trash cans
|
||||
renderFeedback(getActiveFilter());
|
||||
} else {
|
||||
adminLoginError.style.display = 'block';
|
||||
adminPasswordInput.value = '';
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
adminLoginError.style.display = 'block';
|
||||
adminPasswordInput.value = '';
|
||||
adminPasswordInput.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user