From 8958d3f4ebc36a6aad220acb9b4ee52936291861 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Wed, 18 Jun 2025 09:45:29 +0200 Subject: [PATCH] test --- admin-dashboard.html | 231 +++++++++++++++++++++++++++++++++++++++++-- admin.html | 181 +++++++++++++++++++++++++++------ auth.go | 108 +++++++++++++++----- evidence-aut.html | 3 + index.html | 1 + kontakt/index.html | 3 + main.go | 1 + rezervace-aut.html | 20 +--- 8 files changed, 469 insertions(+), 79 deletions(-) diff --git a/admin-dashboard.html b/admin-dashboard.html index ce1fd88..7f05ea0 100644 --- a/admin-dashboard.html +++ b/admin-dashboard.html @@ -1004,11 +1004,12 @@
@@ -1062,7 +1063,62 @@ .logout-btn:hover { background-color: #c0392b; } - + + + +

Vítejte v administraci

@@ -3046,6 +3102,163 @@ async function loadBanner() { // Add submission flag at the top of the script let isSubmitting = false; +// Setup credentials form +function setupCredentialsForm() { + const credentialsForm = document.getElementById('credentialsForm'); + if (!credentialsForm) return; + + credentialsForm.addEventListener('submit', async (e) => { + e.preventDefault(); + + // Prevent multiple submissions + if (isSubmitting) return; + isSubmitting = true; + + const formData = new FormData(credentialsForm); + const currentUsername = formData.get('currentUsername'); + const currentPassword = formData.get('currentPassword'); + const newUsername = formData.get('newUsername'); + const newPassword = formData.get('newPassword'); + const confirmPassword = formData.get('confirmPassword'); + + // Reset previous errors + document.querySelectorAll('.form-control').forEach(el => el.classList.remove('border-red-500')); + const alertEl = document.getElementById('credentialsAlert'); + alertEl.classList.add('hidden'); + + // Client-side validation + let isValid = true; + + if (!currentUsername || !currentPassword) { + showError('Vyplňte prosím aktuální přihlašovací údaje.'); + isValid = false; + } + + if (newPassword && newPassword.length < 8) { + document.getElementById('newPassword').classList.add('border-red-500'); + showError('Nové heslo musí mít alespoň 8 znaků.'); + isValid = false; + } + + if (newPassword !== confirmPassword) { + document.getElementById('confirmPassword').classList.add('border-red-500'); + showError('Nová hesla se neshodují.'); + isValid = false; + } + + if (!isValid) { + isSubmitting = false; + return; + } + + // Prepare request data + const requestData = { + currentUsername, + currentPassword, + newUsername: newUsername || undefined, + newPassword: newPassword || undefined + }; + + try { + const response = await fetch('/api/update-credentials', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${localStorage.getItem('token')}` + }, + body: JSON.stringify(requestData) + }); + + const data = await response.json(); + + if (!response.ok) { + throw new Error(data.error || 'Nepodařilo se aktualizovat přihlašovací údaje'); + } + + // Show success message + showSuccess('Přihlašovací údaje byly úspěšně aktualizovány. Budete odhlášeni za 3 sekundy...'); + + // Logout after a delay + setTimeout(() => { + localStorage.removeItem('token'); + window.location.href = '/login.html'; + }, 3000); + + } catch (error) { + console.error('Chyba při aktualizaci přihlašovacích údajů:', error); + showError(error.message || 'Nastala chyba při aktualizaci přihlašovacích údajů'); + } finally { + isSubmitting = false; + } + }); + + function showError(message) { + const alertEl = document.getElementById('credentialsAlert'); + alertEl.textContent = message; + alertEl.className = 'bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4'; + alertEl.classList.remove('hidden'); + alertEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + } + + function showSuccess(message) { + const alertEl = document.getElementById('credentialsAlert'); + alertEl.textContent = message; + alertEl.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4'; + alertEl.classList.remove('hidden'); + alertEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + } +} + +// Setup navigation +function setupNavigation() { + const navLinks = document.querySelectorAll('.nav-link'); + const sections = document.querySelectorAll('.card[id]'); + + // Show section based on hash or default to first section + function showSection(sectionId) { + // Hide all sections + sections.forEach(section => { + section.style.display = 'none'; + }); + + // Show selected section + const targetSection = document.getElementById(sectionId); + if (targetSection) { + targetSection.style.display = 'block'; + } else if (sections.length > 0) { + // Default to first section if target not found + sections[0].style.display = 'block'; + } + + // Update active nav link + navLinks.forEach(link => { + link.classList.toggle('active', link.getAttribute('data-section') === sectionId); + }); + + // Update URL hash + window.location.hash = `#${sectionId}`; + } + + // Handle nav link clicks + navLinks.forEach(link => { + link.addEventListener('click', (e) => { + e.preventDefault(); + const sectionId = link.getAttribute('data-section'); + showSection(sectionId); + }); + }); + + // Handle initial load + const initialSection = window.location.hash ? window.location.hash.substring(1) : 'aplikace'; + showSection(initialSection); + + // Handle browser back/forward + window.addEventListener('popstate', () => { + const sectionId = window.location.hash ? window.location.hash.substring(1) : 'aplikace'; + showSection(sectionId); + }); +} + async function saveBanner(event) { event.preventDefault(); @@ -4295,6 +4508,12 @@ document.addEventListener('DOMContentLoaded', function() { // Initialize banner image upload functionality const dragDropArea = document.getElementById('dragDropArea'); + + // Initialize credentials form + setupCredentialsForm(); + + // Navigation handling + setupNavigation(); const uploadImageBtn = document.getElementById('uploadImageBtn'); const bannerImageInput = document.getElementById('bannerImage'); diff --git a/admin.html b/admin.html index eeaa5e9..b71a2b9 100644 --- a/admin.html +++ b/admin.html @@ -4,85 +4,202 @@ Admin Login - PP Kunovice + +
@@ -87,6 +88,7 @@ OSticket Kanboard Kontakt + Rezervace aut @@ -319,6 +321,7 @@
  • Objednávka obědů
  • Technická podpora
  • Kontakty
  • +
  • Rezervace aut
  • diff --git a/index.html b/index.html index 3ce0390..4437cfa 100644 --- a/index.html +++ b/index.html @@ -549,6 +549,7 @@
  • Objednávka obědů
  • Technická podpora
  • Kontakty
  • +
  • Rezervace aut
  • diff --git a/kontakt/index.html b/kontakt/index.html index 1b7fa93..467389d 100644 --- a/kontakt/index.html +++ b/kontakt/index.html @@ -60,6 +60,7 @@ OSticket Kanboard Kontakt + Rezervace aut @@ -71,6 +72,7 @@ OSticket Kanboard Kontakt + Rezervace aut @@ -247,6 +249,7 @@
  • Objednávka obědů
  • Technická podpora
  • Kontakty
  • +
  • Rezervace aut
  • diff --git a/main.go b/main.go index 27caec6..2df33b6 100644 --- a/main.go +++ b/main.go @@ -141,6 +141,7 @@ func main() { // Authentication routes r.HandleFunc("/api/login", LoginHandler).Methods("POST", "OPTIONS") + r.HandleFunc("/api/update-credentials", UpdateCredentialsHandler).Methods("POST", "OPTIONS") // Public endpoints (must be defined before protected ones) r.HandleFunc("/api/banner", GetBannerHandler).Methods("GET", "OPTIONS") diff --git a/rezervace-aut.html b/rezervace-aut.html index 479c635..cfa1e92 100644 --- a/rezervace-aut.html +++ b/rezervace-aut.html @@ -922,6 +922,7 @@ OSticket Kanboard Kontakt + Rezervace aut @@ -933,6 +934,7 @@ OSticket Kanboard Kontakt + Rezervace aut @@ -970,20 +972,6 @@ Škoda Fabia - 1Z3 5789 - - - @@ -1044,9 +1032,6 @@ - - - @@ -1173,6 +1158,7 @@
  • Objednávka obědů
  • Technická podpora
  • Kontakty
  • +
  • Rezervace aut