diff --git a/.DS_Store b/.DS_Store index 568a287..d35fe7f 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/account.html b/account.html index 39a32b3..f577650 100644 --- a/account.html +++ b/account.html @@ -23,7 +23,7 @@

FEDL account

Manage your account

-

Update the email tied to your account, change your password, and send yourself a password reset link.

+

Change your password and view your account details.

-

Email

-

Add the inbox you want FEDL to use for account recovery.

-
- -

-
- -
-
-
- -
-

Password reset email

-

Loading reset email settings…

+

Password reset

+

Forgot your password? Request a reset code which will be sent to your messages.

- + Open reset page
diff --git a/app.js b/app.js index 4d058e8..c4c6995 100644 --- a/app.js +++ b/app.js @@ -2880,17 +2880,12 @@ return; } const username = String(qs('signup-username').value || '').trim().toLowerCase(); - const email = String((qs('signup-email') && qs('signup-email').value) || '').trim().toLowerCase(); const password = qs('signup-password').value || ''; const password2 = qs('signup-password2').value || ''; if (!FEDL_USERNAME_RE.test(username)) { setSignupStatus('Use 3–24 characters: lowercase letters, numbers, or underscore only.', 'error'); return; } - if (email && !FEDL_EMAIL_RE.test(email)) { - setSignupStatus('Enter a valid email address.', 'error'); - return; - } if (password.length < 8) { setSignupStatus('Password must be at least 8 characters.', 'error'); return; @@ -2904,7 +2899,7 @@ fetch(liveApiPath('/api/auth/signup'), { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ username, email, password }) + body: JSON.stringify({ username, password }) }).then(async r=>{ const { data, message } = await fedlReadJsonResponse(r); if (!r.ok) { @@ -2984,12 +2979,8 @@ if (page === 'account') { const overviewStatusEl = qs('account-overview-status'); - const emailForm = qs('account-email-form'); - const emailStatusEl = qs('account-email-status'); - const emailInput = qs('account-email'); const accountUsernameEl = qs('account-username'); const accountCreatedEl = qs('account-created'); - const resetSupportEl = qs('account-reset-support'); const resetBtn = qs('account-reset-email-btn'); const resetStatusEl = qs('account-reset-status'); const passwordForm = qs('account-password-form'); @@ -2999,9 +2990,6 @@ function setOverviewStatus(msg, kind){ fedlSetFormStatus(overviewStatusEl, msg, kind); } - function setEmailStatus(msg, kind){ - fedlSetFormStatus(emailStatusEl, msg, kind); - } function setResetStatus(msg, kind){ fedlSetFormStatus(resetStatusEl, msg, kind); } @@ -3040,21 +3028,6 @@ if (accountCreatedEl) { accountCreatedEl.textContent = formatJoinedDate(data.createdAt); } - if (emailInput) { - emailInput.value = data.email || ''; - } - if (resetBtn) { - resetBtn.disabled = !data.email; - } - if (resetSupportEl) { - if (!data.emailDeliveryConfigured) { - resetSupportEl.textContent = 'Password reset email is ready in the app, but the server still needs SMTP configured for help@fedl.site before it can send mail.'; - } else if (!data.email) { - resetSupportEl.textContent = 'Add your email address first, then you can send yourself a reset link from this page.'; - } else { - resetSupportEl.textContent = `Reset emails will be sent to ${data.email} from help@fedl.site once mail delivery is configured with that sender.`; - } - } setOverviewStatus(''); }).catch(err=>{ console.error(err); @@ -3065,54 +3038,22 @@ }); } - if (emailForm) { - emailForm.addEventListener('submit', function(ev){ - ev.preventDefault(); - const email = String(emailInput ? emailInput.value : '').trim().toLowerCase(); - if (!FEDL_EMAIL_RE.test(email)) { - setEmailStatus('Enter a valid email address.', 'error'); - return; - } - setEmailStatus('Saving your email…'); - fetch(liveApiPath('/api/account'), { - method: 'PUT', - headers: authHeaders(), - body: JSON.stringify({ email }) - }).then(async r=>{ - const { message } = await fedlReadJsonResponse(r); - if (!r.ok) { - throw new Error(message || 'Could not update email.'); - } - setEmailStatus('Email updated.', 'success'); - if (resetBtn) { - resetBtn.disabled = false; - } - if (resetSupportEl) { - resetSupportEl.textContent = `Reset emails will be sent to ${email} from help@fedl.site once mail delivery is configured with that sender.`; - } - }).catch(err=>{ - console.error(err); - setEmailStatus(err.message || 'Could not update email.', 'error'); - }); - }); - } - if (resetBtn) { resetBtn.addEventListener('click', function(){ resetBtn.disabled = true; - setResetStatus('Sending reset email…'); + setResetStatus('Sending reset code to your messages…'); fetch(liveApiPath('/api/account/password-reset-email'), { method: 'POST', headers: { Authorization: `Bearer ${fedlGetAuthToken()}` } }).then(async r=>{ const { message } = await fedlReadJsonResponse(r); if (!r.ok) { - throw new Error(message || 'Could not send reset email.'); + throw new Error(message || 'Could not send reset code.'); } - setResetStatus('Reset email sent. Check your inbox for a link from help@fedl.site.', 'success'); + setResetStatus('Reset code sent! Check your messages.', 'success'); }).catch(err=>{ console.error(err); - setResetStatus(err.message || 'Could not send reset email.', 'error'); + setResetStatus(err.message || 'Could not send reset code.', 'error'); }).finally(()=>{ resetBtn.disabled = false; }); @@ -3212,11 +3153,14 @@ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ identifier }) }).then(async r=>{ - const { message } = await fedlReadJsonResponse(r); + const data = await fedlReadJsonResponse(r); if (!r.ok) { - throw new Error(message || 'Could not request password reset.'); + throw new Error(data.message || 'Could not request password reset.'); + } + setRequestStatus(data.message || 'Check your messages for the reset code.', 'success'); + if (requestInput) { + requestInput.value = ''; } - setRequestStatus('If that account has an email on file, we sent a reset link.', 'success'); }).catch(err=>{ console.error(err); setRequestStatus(err.message || 'Could not request password reset.', 'error'); @@ -3239,7 +3183,7 @@ const newPassword = String(qs('reset-new-password').value || ''); const confirmPassword = String(qs('reset-confirm-password').value || ''); if (!token) { - setResetPasswordStatus('Paste the reset token or open the link from your email.', 'error'); + setResetPasswordStatus('Paste the reset code below.', 'error'); return; } if (newPassword.length < 8) { diff --git a/messages.html b/messages.html index c68f650..41c69b4 100644 --- a/messages.html +++ b/messages.html @@ -24,6 +24,8 @@ .dm-message{padding:12px 16px;border-radius:12px;max-width:70%;word-wrap:break-word} .dm-message.sent{background:var(--accent);color:#042;align-self:flex-end;border-bottom-right-radius:4px} .dm-message.received{background:rgba(255,255,255,0.1);align-self:flex-start;border-bottom-left-radius:4px} + .dm-message.system{background:rgba(255,184,77,0.12);border:1px solid rgba(255,184,77,0.25);align-self:stretch;max-width:90%} + .dm-message.system .dm-message-content{white-space:pre-wrap} .dm-message-time{font-size:0.7rem;opacity:0.7;margin-top:4px} .dm-input-row{display:flex;gap:12px;padding:16px;border-top:1px solid rgba(255,255,255,0.1)} .dm-input-row input{flex:1;padding:12px;border-radius:8px;border:1px solid rgba(255,255,255,0.1);background:rgba(255,255,255,0.05);color:var(--text);font-size:1rem} @@ -159,17 +161,35 @@ function renderConversations() { const list = document.getElementById('conversationsList'); - if (!conversations.length) { + + const hasSystemMessages = conversations.some(c => c.userId === 'system'); + const userConversations = conversations.filter(c => c.userId !== 'system'); + + let html = ''; + + if (hasSystemMessages) { + html += ` +
+
System Notifications
+
Password resets and alerts
+
+ `; + } + + if (!userConversations.length && !hasSystemMessages) { list.innerHTML = '
No conversations yet
'; return; } - list.innerHTML = conversations.map(c => ` + + html += userConversations.map(c => `
${escapeHtml(c.username)}
${escapeHtml(c.lastMessage.content)}
${formatDate(c.lastMessage.timestamp)}
`).join(''); + + list.innerHTML = html; list.querySelectorAll('.dm-conversation').forEach(el => { el.addEventListener('click', () => selectConversation(el.dataset.user)); }); @@ -177,11 +197,25 @@ function selectConversation(userId) { selectedConversation = userId; - const conv = conversations.find(c => c.userId === userId); - document.getElementById('chatWithName').textContent = conv ? conv.username : 'Chat'; - document.getElementById('messageInputRow').hidden = false; + if (userId === 'system') { + document.getElementById('chatWithName').textContent = 'System Notifications'; + document.getElementById('messageInputRow').hidden = true; + loadSystemMessages(); + } else { + const conv = conversations.find(c => c.userId === userId); + document.getElementById('chatWithName').textContent = conv ? conv.username : 'Chat'; + document.getElementById('messageInputRow').hidden = false; + loadMessages(userId); + } renderConversations(); - loadMessages(userId); + } + + function loadSystemMessages() { + api('/api/messages/system').then(res => { + if (res.ok && res.data && res.data.messages) { + renderMessages(res.data.messages, true); + } + }); } function loadMessages(userId) { @@ -192,18 +226,24 @@ }); } - function renderMessages(messages) { + function renderMessages(messages, isSystem = false) { const list = document.getElementById('messagesList'); if (!messages.length) { - list.innerHTML = '
No messages yet. Start the conversation!
'; + list.innerHTML = '
No messages yet.
'; return; } - list.innerHTML = messages.map(m => ` -
-
${escapeHtml(m.content)}
-
${formatDate(m.timestamp)}
-
- `).join(''); + list.innerHTML = messages.map(m => { + const isCode = m.type === 'password_reset'; + const content = isCode + ? `${escapeHtml(m.content)}` + : escapeHtml(m.content); + return ` +
+
${content}
+
${formatDate(m.timestamp)}
+
+ `; + }).join(''); list.scrollTop = list.scrollHeight; } diff --git a/reset-password.html b/reset-password.html index 03a9f68..d873cfa 100644 --- a/reset-password.html +++ b/reset-password.html @@ -21,26 +21,27 @@

FEDL account

-

Request a reset link

-

Enter your username or email and FEDL will send a reset link to the email saved on that account.

+

Request a reset code

+

Enter your username to get a reset code sent to your messages.

- +
-
-

Use your reset link

-

If you opened the email link on this page, the token should already be filled in.

+