1import { a as auth } from './auth-BoPu1Kik.js'; 2import { p as profile } from './profile-b4k2y0dV.js'; 3import { l as loading, d as doneLoading } from './loading-CnaT4-R9.js'; 4import { d as settings, g as globalStore } from './main-module-Dg7u5i1g.js'; 5import { s as security } from './security-CjMZ7P28.js'; 6 7const login={returnObject:{success:false,error:null},/** 8 * @param {object} data - containing email and password 9 */login:async data=>{if(!data){login.returnObject.success=false;login.returnObject.error='Beiden velden zijn verplicht';return login.returnObject;}if(!data['email']||data.email.length<=0){login.returnObject.success=false;login.returnObject.error='E-mailadres is verplicht';return login.returnObject;}if(!data['password']){login.returnObject.success=false;login.returnObject.error='Wachtwoord is verplicht';return login.returnObject;}// Sanatize values 10data.email=security.dompurifySanatize(data.email);data.password=security.dompurifySanatize(data.password);try{const response=await auth.login(data);
10if(response['api_token']){globalStore.api_token=response.api_token;localStorage.setItem('user',JSON.stringify(response.user));localStorage.setItem('api_token',JSON.stringify(response.api_token));let userObject=JSON.parse(localStorage.getItem('user'));let profileResponse=await profile.get({include:'preferences'});// Let's create a profile if there is none 11if(profileResponse.status&&profileResponse.status===403){let newsletterBoolean=localStorage.getItem('newsletter');localStorage.removeItem('newsletter');let createProfileResponse=await profile.post({newsletter:newsletterBoolean});}else if(profileResponse.status&&profileResponse.status===401){console.error("Couldn't login",profileResponse);}if(profileResponse.preferences&&profileResponse.preferences.group_size&&profileResponse.preferences.personality&&profileResponse.preferences.training_type){userObject.preferences=profileResponse.preferences;localStorage.setItem('user',JSON.stringify(userObject));}login.returnObject.success=true;login.returnObject.error=null;return login.returnObject;}else {if(response['errors']){if(response.errors['email']&&response.errors.email.length>0){throw new Error(response.errors.email[0]);}else if(response.errors['password']&&response.errors.password.length>0){throw new Error(response.errors.password[0]);}// Fall back to the first error from any other field 12const firstField=Object.keys(response.errors)[0];if(firstField&&Array.isArray(response.errors[firstField])&&response.errors[firstField].length>0){console.log('first');throw new Error(response.errors[firstField][0]);}}throw new Error('E-mailadres en/of wachtwoord is onjuist');}}catch(error){login.returnObject.success=false;login.returnObject.error=error.message;return login.returnObject;}}};(function(){const loginComponents=document.querySelectorAll('.js-login');loginComponents.forEach(component=>{let loginButton;const selector=component.getAttribute('data-id');if(selector){loginButton=document.querySelector('.js-login-button[data-id="'+selector+'"]');}else {loginButton=component.querySelector('.js-login-button');}if(!loginButton){console.error('Login button could not be found');return;}const emailInput=component.querySelector('.js-email-input');const passwordInput=component.querySelector('.js-password-input');const visible=component.querySelector('.js-visible');const invisible=component.querySelector('.js-invisible');const togglePasswordButton=component.querySelector('.js-toggle-password');const invalidDiv=component.querySelector('.js-invalid');loginButton.addEventListener('click',async()=>{loading();const response=await login.login({email:emailInput.value,password:passwordInput.value});
12if(!response.success){invalidDiv.innerHTML=response.error;invalidDiv.style.display='block';console.error(response.error);// Show a resend verification button if the email is not verified 13const existingResend=component.querySelector('.js-resend-verification');if(existingResend)existingResend.remove();if(response.error&&response.error.includes('geverifieerd')){const resendWrapper=document.createElement('div');resendWrapper.className='js-resend-verification mt-3';const resendButton=document.createElement('button');resendButton.className='c-button-outline js-loading js-loading-black';resendButton.textContent='Verzend verificatiemail opnieuw';const resendMessage=document.createElement('p');resendMessage.className='mt-2 text-sm text-success';resendMessage.style.display='none';resendMessage.textContent='Mail is opnieuw verzonden';resendButton.addEventListener('click',async()=>{loading();try{const resendResponse=await auth.resendEmail({email:emailInput.value,app:settings.moveSlug});if(resendResponse.user){resendButton.replaceWith(resendMessage);resendMessage.style.display='block';}}catch(err){console.error(err);}doneLoading();});resendWrapper.appendChild(resendButton);resendWrapper.appendChild(resendMessage);invalidDiv.after(resendWrapper);}}else {location.reload();}doneLoading();});togglePasswordButton.addEventListener('click',()=>{if(passwordInput.type==="password"){visible.style.display='block';invisible.style.display='none';passwordInput.type="text";togglePasswordButton.setAttribute('aria-label','Wachtwoord verbergen');}else {visible.style.display='none';invisible.style.display='block';passwordInput.type="password";togglePasswordButton.setAttribute('aria-label','Wachtwoord tonen');}});});})(); 14 15export { login };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.