'use strict';dotclear.ready(()=>{const currentPasswordField=document.getElementById('cur_pwd');if(!currentPasswordField)return;const emailField=document.getElementById('user_email');const newPasswordField=document.getElementById('new_pwd');const userEmail=emailField?.value;const needPassword=()=>{if(emailField?.value!==userEmail)return true;return!!newPasswordField?.value;};const userprefsData=dotclear.getData('userprefs');emailField?.addEventListener('change',()=>{if(needPassword())currentPasswordField.setAttribute('required','true');else currentPasswordField.removeAttribute('required');});newPasswordField?.addEventListener('change',()=>{if(needPassword())currentPasswordField.setAttribute('required','true');else currentPasswordField.removeAttribute('required');});dotclear.passwordStrength(dotclear.getData('pwstrength'));dotclear.responsiveCellHeaders(document.querySelector('#user_options_lists_container table'),'#user_options_lists_container table',0,true,);const remove=document.getElementById('removeaction');remove?.addEventListener('click',(event)=>dotclear.confirm(userprefsData.remove,event));dotclear.webAuthnRegistration=()=>{var wanHelper={atb:(b)=>{const u=new Uint8Array(b);let s='';for(let i=0;i<u.byteLength;i++){s+=String.fromCharCode(u[i]);}
return btoa(s);},bta:(o)=>{const pre='=?BINARY?B?';const suf='?=';for(const k in o){if(typeof o[k]==='string'){const s=o[k];if(s.startsWith(pre)&&s.endsWith(suf)){const b=globalThis.atob(s.substring(pre.length,s.length-suf.length));const u=new Uint8Array(b.length);for(let i=0;i<b.length;i++){u[i]=b.charCodeAt(i);}
o[k]=u.buffer;}}else{wanHelper.bta(o[k]);}}},};try{if(!('credentials'in navigator)){throw new Error('Browser not supported.');}
const passkeyLabel=prompt(userprefsData.passkeylabel,'');dotclear.jsonServicesPost('webAuthnRegistration',(prepareCreate)=>{if(prepareCreate.success===false){throw new Error(prepareCreate.message||'unknown error occured');}
wanHelper.bta(prepareCreate.arguments);navigator.credentials.create(prepareCreate.arguments).then((publicKeyCredential)=>{dotclear.jsonServicesPost('webAuthnRegistration',(processCreate)=>{if(processCreate.success===false){throw new Error(prepareCreate.message||'unknown error occured');}
globalThis.location.reload();},{json:1,step:'process',label:(passkeyLabel||'').toString(),client:publicKeyCredential.response.clientDataJSON?wanHelper.atb(publicKeyCredential.response.clientDataJSON):null,attestation:publicKeyCredential.response.attestationObject?wanHelper.atb(publicKeyCredential.response.attestationObject):null,transports:publicKeyCredential.response.getTransports?wanHelper.atb(publicKeyCredential.response.getTransports()):null,},(error)=>{console.log(error||'unknown error occured');},);}).catch((error)=>{console.log(error||'unknown error occured');});},{json:1,step:'prepare',},(error)=>{console.log(error||'unknown error occured');},);}catch(error){console.log(error.message||'unknown error occured');}};if('credentials'in navigator){$('#webauthn_action input').on('click',(e)=>{dotclear.webAuthnRegistration();e.preventDefault();e.returnValue='';});}else{$('#webauthn_action').hide();}});