feat: Implement user profile management and navigation updates
- Added a new profile page (my_profil.html) for users to manage their events and personal information. - Introduced a new CSS file (my_profil.css) for styling the profile page. - Created a JavaScript file (my_profil.js) to handle profile data retrieval, event registration management, and form submission. - Updated navigation logic (navigation.js) to dynamically display login/signup or event management links based on user authentication status. - Enhanced event creation and detail pages to support user-specific actions (registration/unregistration). - Improved login and signup processes to handle user data more robustly, including fallback user creation. - Refactored event overview to show user-specific events and registrations. - Added error handling and validation for user input in profile management.
This commit is contained in:
1 parent
46074df578
commit
1efa4dcd39
17 files changed
+1076
-29
No files matched your search
+49
-3
@@ -4,6 +4,42 @@ const passwortInput = document.getElementById('passwort');
|
||||
const emailError = document.getElementById('emailError');
|
||||
const passwortError = document.getElementById('passwortError');
|
||||
|
||||
const USERS_STORAGE_KEY = 'socialCookingUsers';
|
||||
const CURRENT_USER_KEY = 'socialCookingCurrentUser';
|
||||
|
||||
// Liest alle registrierten Benutzer robust aus localStorage.
|
||||
function getStoredUsers() {
|
||||
try {
|
||||
const raw = localStorage.getItem(USERS_STORAGE_KEY);
|
||||
return raw ? JSON.parse(raw) : [];
|
||||
} catch (error) {
|
||||
console.error('Benutzerdaten konnten nicht gelesen werden.', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Speichert den aktiven Benutzer fuer nachfolgende Seiten.
|
||||
function setCurrentUser(user) {
|
||||
localStorage.setItem(CURRENT_USER_KEY, JSON.stringify(user));
|
||||
}
|
||||
|
||||
// Erstellt einen Demo-Benutzer, falls fuer die E-Mail noch kein Account existiert.
|
||||
function createFallbackUser(email, passwort) {
|
||||
const localPart = email.split('@')[0] || 'Gast';
|
||||
const normalized = localPart.replace(/[._-]/g, ' ').trim();
|
||||
const guessedVorname = normalized ? normalized.split(' ')[0] : 'Gast';
|
||||
|
||||
return {
|
||||
id: Date.now(),
|
||||
vorname: guessedVorname.charAt(0).toUpperCase() + guessedVorname.slice(1),
|
||||
nachname: '',
|
||||
email,
|
||||
passwort,
|
||||
createdAt: new Date().toISOString(),
|
||||
source: 'login-fallback'
|
||||
};
|
||||
}
|
||||
|
||||
// Validierungsfunktion
|
||||
function validateForm(event) {
|
||||
event.preventDefault();
|
||||
@@ -43,11 +79,21 @@ function validateForm(event) {
|
||||
passwortGroup.classList.remove('has-error');
|
||||
}
|
||||
|
||||
// Wenn alle Validierungen bestanden, Form absenden
|
||||
// Wenn alle Validierungen bestanden, Benutzer pruefen und Session speichern.
|
||||
if (isValid) {
|
||||
//alert('Login erfolgreich! (Dies ist eine Demo)');
|
||||
const users = getStoredUsers();
|
||||
const matchedUser = users.find(user => user.email?.toLowerCase() === emailValue.toLowerCase());
|
||||
|
||||
// Weiterleitung zur event overview Page
|
||||
if (matchedUser && matchedUser.passwort !== passwortValue) {
|
||||
passwortGroup.classList.add('has-error');
|
||||
passwortError.textContent = 'Das Passwort ist nicht korrekt.';
|
||||
return;
|
||||
}
|
||||
|
||||
const userToLogin = matchedUser || createFallbackUser(emailValue, passwortValue);
|
||||
setCurrentUser(userToLogin);
|
||||
|
||||
// Weiterleitung zur Event-Overview-Seite.
|
||||
window.location.href = 'event_overview.html';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user