Add Profile modal and Logout button for logged-in users
This commit is contained in:
+47
@@ -33,10 +33,12 @@ function checkSession() {
|
||||
if (news) news.classList.add('hidden');
|
||||
if (login) login.classList.add('hidden');
|
||||
if (notebook) notebook.classList.remove('hidden');
|
||||
document.querySelectorAll('.user-actions').forEach(el => el.classList.remove('hidden'));
|
||||
} else {
|
||||
if (notebook) notebook.classList.add('hidden');
|
||||
if (login) login.classList.remove('hidden');
|
||||
if (newsletter) newsletter.classList.remove('hidden');
|
||||
document.querySelectorAll('.user-actions').forEach(el => el.classList.add('hidden'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +168,9 @@ async function submitLoginData() {
|
||||
document.getElementById('news-col').classList.add('hidden');
|
||||
document.getElementById('login-panel').classList.add('hidden');
|
||||
document.getElementById('notebook-panel').classList.remove('hidden');
|
||||
document.getElementById('profile-username').value = document.getElementById('telegram-user').value;
|
||||
document.getElementById('profile-name').value = document.getElementById('full-name').value;
|
||||
document.getElementById('profile-llc').value = document.getElementById('llc-name').value;
|
||||
alert('Erfolgreich angemeldet! Willkommen!');
|
||||
} else {
|
||||
alert('Fehler bei der Anmeldung.');
|
||||
@@ -247,4 +252,46 @@ function filterUsers(searchTerm) {
|
||||
const text = card.innerText.toLowerCase();
|
||||
card.style.display = text.includes(term) ? 'block' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
function openProfileModal() {
|
||||
document.getElementById('profile-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeProfileModal() {
|
||||
document.getElementById('profile-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function logout() {
|
||||
setCookie('sessionid', '', -1);
|
||||
checkSession();
|
||||
closeProfileModal();
|
||||
}
|
||||
|
||||
async function saveProfile() {
|
||||
const name = document.getElementById('profile-name').value.trim();
|
||||
const llc = document.getElementById('profile-llc').value.trim();
|
||||
if (!name || !llc) { alert('Bitte geben Sie Name und LLC-Namen ein.'); return; }
|
||||
|
||||
try {
|
||||
const response = await fetch(API_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: document.getElementById('profile-username').value,
|
||||
name: name,
|
||||
llc: llc
|
||||
})
|
||||
});
|
||||
console.log('saveProfile response:', response.status, await response.clone().json());
|
||||
if (response.ok) {
|
||||
alert('Profil erfolgreich gespeichert!');
|
||||
closeProfileModal();
|
||||
} else {
|
||||
alert('Fehler beim Speichern.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('saveProfile error:', error);
|
||||
alert('Fehler bei der Verbindung.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user