From 65b0ee8e0b3af19bd57f07e337068eeea210a09f Mon Sep 17 00:00:00 2001 From: David Date: Thu, 29 Jan 2026 18:20:35 +1100 Subject: [PATCH] PostIdentifyandloggout --- script.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index 53db3c6..0ab6609 100644 --- a/script.js +++ b/script.js @@ -113,6 +113,32 @@ document.addEventListener('DOMContentLoaded', () => { let generatedOTP = null; let newAvatarBase64 = null; + // --- CHECK SESSION & LOGOUT --- + function checkSession() { + const currentUser = JSON.parse(localStorage.getItem('currentUser') || '{}'); + if (currentUser.email) { + if (loginView) { + loginView.classList.add('hidden'); + loginView.style.display = 'none'; + } + if (feedView) { + feedView.classList.remove('hidden'); + initFeed(); + } + } + } + checkSession(); + + const logoutBtn = document.querySelector('.header-actions .icon-btn'); + if (logoutBtn) { + logoutBtn.addEventListener('click', () => { + if (confirm('Log out?')) { + localStorage.removeItem('currentUser'); + location.reload(); + } + }); + } + // --- ONBOARDING LOGIC --- // Avatar Upload Handler if (avatarTrigger && avatarInput) { @@ -407,20 +433,29 @@ document.addEventListener('DOMContentLoaded', () => { article.setAttribute('data-post-id', post.id); const currentUser = JSON.parse(localStorage.getItem('currentUser') || '{}'); - const isOwner = post.userEmail && post.userEmail === currentUser.email; + const currentEmail = (currentUser.email || '').trim().toLowerCase(); + const postEmail = (post.userEmail || '').trim().toLowerCase(); - // Only show options if owner - const optionsHTML = isOwner ? ` + // STRICT MODE: Email Only (as requested by User) + // This disables deleting legacy posts without email, but ensures security. + const isOwner = (postEmail && postEmail === currentEmail); + + // Always show the trigger, but vary the menu content + const optionsHTML = `
+ ${isOwner ? ` + ` : ` + + `}
- ` : ''; + `; let slidesHTML = ''; let dotsHTML = ''; @@ -572,7 +607,13 @@ document.addEventListener('DOMContentLoaded', () => { const postToDelete = userPosts.find(p => p.id === id); const currentUser = JSON.parse(localStorage.getItem('currentUser') || '{}'); - if (!postToDelete || postToDelete.userEmail !== currentUser.email) { + // STRICT MODE: Email Only + const currentEmail = (currentUser.email || '').trim().toLowerCase(); + const postEmail = (postToDelete.userEmail || '').trim().toLowerCase(); + const isOwner = (postEmail && postEmail === currentEmail); + + if (!postToDelete || !isOwner) { + console.log('Delete blocked. Owner Check Failed.'); alert('You can only delete your own posts.'); return; }