7 lines
4.5 KiB
JavaScript
7 lines
4.5 KiB
JavaScript
import {mailHero,serviceTabs} from './mail-service-ui.mjs';
|
|
import {signatureTools} from './mail-signature.mjs';
|
|
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
|
const dashboard=document.getElementById('dashboard');let section=null,link=null;
|
|
async function load(){try{const r=await fetch('/api/mail/me',{cache:'no-store'});if(!r.ok)return remove();const data=await r.json();if(!data.linked)return remove();if(!section){section=el('section');section.id='webmail';section.className='git-control-page';section.append(mailHero('DuneRealms Mail','YOUR MAIL WORKSPACE','Your verified mailbox, security and DuneRealms branding in one place.'));const accessPanel=el('div');const card=el('div');card.className='git-control-summary';const details=el('div');details.append(el('small','Verified mailbox'),el('strong',data.address));card.append(details);const actions=el('div');actions.className='git-control-actions';const open=el('a','Open webmail ↗');open.href='https://www.lgbbenelux.org/webmail/';open.target='_blank';open.rel='noopener noreferrer';actions.append(open);accessPanel.append(card,actions,el('p','Webmail opens separately to protect your mailbox session. Sign in with your existing mailbox credentials.'));const setup=el('details');setup.append(el('summary',data.needsPasswordSetup?'Set up your mailbox password':'Change mailbox password'));const form=el('form');form.className='site-profile-form';const result=el('p');result.role='status';function field(label,name){const box=el('label',label),input=el('input');input.type='password';input.name=name;input.minLength=12;input.maxLength=256;input.required=true;input.autocomplete=name==='currentPassword'?'current-password':'new-password';box.append(input);form.append(box);return input;}const current=field('Confirm your current DuneRealms website password','currentPassword'),password=field('New mailbox password','newPassword'),confirm=field('Repeat new mailbox password','confirmPassword');const sameLabel=el('label'),same=el('input');same.type='checkbox';sameLabel.append(same,document.createTextNode('Use my current website password for this mailbox once (optional; future website password changes will not sync)'));form.append(sameLabel);same.onchange=()=>{for(const input of [password,confirm]){input.disabled=same.checked;input.required=!same.checked;input.value='';}};const submit=el('button','Save mailbox password');submit.type='submit';submit.disabled=!data.setupAvailable;form.append(submit,result);setup.append(form,el('p','This changes only your own mailbox password. Website login and service mailboxes are unaffected.'));if(!data.setupAvailable)setup.append(el('p','Mailbox password setup is being prepared. Existing webmail access remains available.'));form.onsubmit=async event=>{event.preventDefault();if(!same.checked&&password.value!==confirm.value){result.textContent='The new passwords do not match.';return;}submit.disabled=true;try{const response=await fetch('/api/mail/password',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({currentPassword:current.value,useSamePassword:same.checked,...(!same.checked?{newPassword:password.value}:{})})});const value=await response.json();if(!response.ok)throw Error(value.message||'Mailbox password could not be saved.');form.reset();same.onchange();result.textContent=value.message;setup.querySelector('summary').textContent='Change mailbox password';}catch(error){result.textContent=error.message;}finally{current.value='';submit.disabled=false;}};section.className+=' mail-service-workspace';section._tabs=serviceTabs(section,[{key:'webmail',label:'Webmail',icon:'nav-support-v2.webp',build:p=>p.append(accessPanel)},{key:'security',label:'Account Security',icon:'nav-account-v2.webp',build:p=>p.append(setup)},{key:'signature',label:'Email Signature',icon:'seals/department-support-150.png',build:p=>p.append(signatureTools())},{key:'templates',label:'Email Templates',icon:'nav-manual-v2.webp',build:p=>p.append(signatureTools({template:true}),signatureTools({template:true,reply:true}))}],{parameter:'mail-tab',id:'mail-service'});dashboard?.append(section);link=el('a','Webmail');link.href='#webmail';dashboard?.querySelector('nav')?.append(link);}}catch{remove();}}
|
|
function remove(){section?._tabs?.dispose();section?.remove();link?.remove();section=null;link=null;}
|
|
window.addEventListener('dune:session',e=>e.detail?load():remove());const session=await fetch('/api/auth/session',{cache:'no-store'});if(session.ok&&(await session.json()).authenticated)load();
|

Staff