PageSourceSearch

https://www.salon-smeonline.com/assets/matrixjs/auth.js

js salon-smeonline.com collected 2026-10-10 00:39:11 UTC 24,848 bytes, 807 lines download raw bytes

1function signup() {
2	if( typeof checkBeforeSubmit !== 'undefined' ){
3		var error = checkBeforeSubmit();
4		if( error ){
5			alert(error);
6			return false;
7		}
8	}
9	
10	var email = document.getElementById('inputEmail');
11	var email2 = document.getElementById('inputEmail2');
12	var password = document.getElementById('inputPassword');
13	var verifyPassword = document.getElementById('inputConfirmPassword');
14
15  if( password === null ){
16    var passwordVal = 'XXX';
17  }else{
18    var passwordVal = password.value;
19  }
20  if( verifyPassword === null ){
21    var verifyPasswordVal = 'XXX';
22  }else{
23    var verifyPasswordVal = password.value;
24  }
25
26	if (passwordVal != verifyPasswordVal) {
27		alert($t('passwordMissmatch'));
28	} else if (email2 && (email2.value != email.value)) {
29		alert($t('emailMissmatch'));
30	} else if (document.getElementById('condition') && !$('#condition').prop('checked')) {
31		alert($t('generalRequirementsRequired'));
32	} else {
33		const fields = $('form').serializeArray();
34		let input = {
35				showId: salon_id
36		};
37
38		for (let index = 0; index < fields.length; index++) {
39			const element = fields[index];
40			input = {
41					...input,
42					[element['name']]: element['value']
43			};
44		}
45    
46    if( passwordVal == 'XXX' && verifyPasswordVal == 'XXX' ){
47      input['inputPassword'] = uuidv4();
48      input['inputConfirmPassword'] = input['inputPassword'];
49    }
50		
51		var functionName = salon_id + 'LambdAuthCreateUser';
52		var lambda = new AWS.Lambda();
53		lambda.invoke({
54			FunctionName: functionName,
55			Payload: JSON.stringify(input)
56		}, function(err, data) {
57			if (data.FunctionError) console.log(data);
58			else {
59				var output = parse(data.Payload);
60				if (output.created) {
61					var pageUrl = new URL(window.location);
62			    loc = confirmation_link+pageUrl.search;
63          var operator = '?';
64          if( loc.includes('?') ){
65            operator = '&';
66          }
67					if( typeof last_page === "undefined" || last_page ){
68						loc += operator+`email=${encodeURIComponent(email.value)}`;
69					}else if( typeof last_page !== "undefined" && !last_page ){
70						loc += operator+`email=${encodeURIComponent(output.emailHash)}`;
71					}
72					if (output.guid) {
73						loc = loc + '&id=' + output.guid;
74					}
75					window.location.href = loc;
76				} else {
77					if (data.StatusCode === 200) {
78						if (output.errorMessage) {
79							alert($t(output.errorMessage));
80						} else {
81							alert($t('emailAlreadyUsed'));
82						}
83					} else alert($t('accountCreationError'));
84				}
85			}
86		});
87	}
88}
89
90function signup2(){
91	var email;
92	const fields = $('form').serializeArray();
93	let input = {
94			showId: salon_id
95	};
96
97	for (let index = 0; index < fields.length; index++) {
98		const element = fields[index];
99		input = {
100				...input,
101				[element['name']]: element['value']
102		};
103	}
104	
105	var functionName = salon_id + 'LambdAuthWriteUser';
106	var lambda = new AWS.Lambda();
107	lambda.invoke({
108		FunctionName: functionName,
109		Payload: JSON.stringify(input)
110	}, function(err, data) {
111		if (data.FunctionError) console.log(data);
112		else {
113			var output = parse(data.Payload);
114      var pageUrl = new URL(window.location);
115			loc = confirmation_link+pageUrl.search;
116      var operator = '?';
117      if( loc.includes('?') ){
118        operator = '&';
119      }
120			if( typeof last_page === "undefined" || last_page ){
121				var val = false;
122				if( typeof email !== "undefined" && email ){
123					val = email.value;
124				}else if( output.email ){
125					val = output.email;
126				}
127				if( val ){
128					loc += operator+`email=${encodeURIComponent(val)}`;
129				}
130			}else if( typeof last_page !== "undefined" && !last_page ){
131				if(!output.emailHash && typeof first_page_url !== 'undefined'){
132          var operator = '?';
133          if( first_page_url.includes('?') ){
134            operator = '&';
135          }
136					loc = first_page_url + operator + 'emailError';
137				}else{
138					loc += operator+`email=${encodeURIComponent(output.emailHash)}`;
139				}
140			}
141			if (output.guid) {
142				loc = loc + '&id=' + output.guid;
143			}
144			window.location.href = loc;
145		}
146	});
147}
148
149function setEmailHashInForm(){
150	if( $('#signup-form').length > 0 ){
151        let searchParams = new URLSearchParams(window.location.search);
152        if( searchParams.has('email') ){
153        	$('<input>', {
154			    id: 'emailHash',
155			    name: 'emailHash',
156			    type: 'hidden',
157			    value: searchParams.get('email'),
158			}).appendTo('#signup-form');
159        }else{
160        	if( typeof first_page_url !== 'undefined' ){
161            var operator = '?';
162            if( first_page_url.includes('?') ){
163              operator = '&';
164            }
165        		window.location = first_page_url + operator + 'emailError';
166        	}
167        }
168    }
169}
170
171function recommandation(){
172	var lambda = new AWS.Lambda();
173	
174	var functionName = salon_id + 'LambdAuthReco';
175	var datas = {
176		userName: $('#inputPrenom').val(),
177		userEmail: $('#inputEmail').val(),
178		emails: [$('#InputEmail1').val(),$('#InputEmail2').val(),$('#InputEmail3').val(),$('#InputEmail4').val()].filter(function(v){return v!==''}),
179		subject: 'On vous recommande le salon virtuel',
180	};
181	
182	lambda.invoke({
183		FunctionName: functionName,
184		Payload: JSON.stringify(datas)
185	}, function(err, data) {
186		if (data == null || data.FunctionError) console.log(data);
187		else {
188			var output = parse(data.Payload);
189			if (output.sent) {
190				alert($t('recoEmailSent'));
191				loginRequired();
192			} else {
193				alert($t('recoEmailFailed'));
194			}
195		}
196	});
197}
198
199function lostPassword() {
200  var lambda = new AWS.Lambda();
201  var email = document.getElementById('inputEmail');
202
203  if (email.value == null || email.value == '') {
204    alert($t('emailRequired'));
205  } else {
206    var input = {
207      email: email.value
208    };
209
210    var functionName = salon_id + 'LambdAuthLostPassword';
211    lambda.invoke({
212      FunctionName: functionName,
213      Payload: JSON.stringify(input)
214    }, function(err, data) {
215      if (data.FunctionError) console.log(data);
216      else {
217        var output = parse(data.Payload);
218        if (output.sent) {
219          alert($t('reinitEmailSent'));
220          loginRequired();
221        } else {
222          alert($t('reinitEmailFailed'));
223        }
224      }
225    });
226  }
227}
228
229function resetPassword(callback) {
230  var lambda = new AWS.Lambda();
231  var lost = findGetParameter('lost');
232  var email = findGetParameter('email');
233  var newPassword = document.getElementById('inputPassword');
234  var verifyNewPassword = document.getElementById('inputConfirmPassword');
235
236  if (newPassword.value == null || newPassword.value == '') {
237    alert($t('passwordRequired'));
238  } else if (newPassword.value != verifyNewPassword.value) {
239    alert($t('passwordMissmatch'));
240  } else {
241    if (((!email)||(!lost)) && salon_id != 15) {
242      alert($t('brokenLink'));
243    } else if (salon_id == 15 && !document.getElementById('email').value) {
244      alert($t('emailRequired'));
245    } else {
246      var input = {
247        email: email || document.getElementById('email').value,
248        lost: lost,
249        password: newPassword.value
250      };
251
252      var functionName = salon_id + 'LambdAuthResetPassword';
253      lambda.invoke({
254        FunctionName: functionName,
255        Payload: JSON.stringify(input)
256      }, function(err, data) {
257        if (data.FunctionError) {
258          console.log(data);
259          alert($t('passwordResetFailed'));
260        } else {
261          var output = parse(data.Payload);
262          if (output.changed) {
263            alert($t('passwordChangedSuccess'));
264            if (typeof callback !== 'undefined'){
265          	  callback();
266            }else{
267          	  loginRequired();
268            }
269          } else {
270            alert($t('unknownError'));
271          }
272        }
273      });
274    }
275  }
276}
277
278function changePassword() {
279  var lambda = new AWS.Lambda();
280  var email = document.getElementById('email');
281  var oldPassword = document.getElementById('old-password');
282  var newPassword = document.getElementById('new-password');
283  var verifyNewPassword = document.getElementById('verify-new-password');
284
285  if (email.value == null || email.value == '') {
286    alert($t('emailRequired'));
287  } else if (oldPassword.value == null || oldPassword.value == '') {
288    alert($t('currentPasswordRequired'));
289  } else if (password.value == null || password.value == '') {
290    alert($t('passwordRequired'));
291  } else if (password.value != verifyNewPassword.value) {
292    alert($t('passwordMissmatch'));
293  } else {
294    var input = {
295      email: email.value,
296      password: oldPassword.value
297    };
298
299    var functionName = salon_id + 'LambdAuthLogin';
300    lambda.invoke({
301      FunctionName: functionName,
302      Payload: JSON.stringify(input)
303    }, function(err, data) {
304      if (data.FunctionError) console.log(data);
305      else {
306        var output = parse(data.Payload);
307        if (!output.login) {
308        	if( typeof customFailedLoginMsg !== "undefined" && customFailedLoginMsg ){
309        		alert(customFailedLoginMsg);
310        	}else{
311        		alert($t('authFailed'));
312        	}
313        } else {
314          AWS.config.credentials = new AWS.CognitoIdentityCredentials({
315              IdentityPoolId: idPoolId,
316              IdentityId: output.identityId,
317              Logins: {
318                  'cognito-identity.amazonaws.com': output.token
319              }
320          });
321
322          var input = {
323              email: email.value,
324            oldPassword: oldPassword.value,
325              newPassword: newPassword.value
326          };
327
328        var functionName = salon_id + 'LambdAuthChangePassword';
329        lambda.invoke({
330            FunctionName: functionName,
331            Payload: JSON.stringify(input)
332         }, function(err, data) {
333            if (data.FunctionError) console.log(data);
334            else {
335                var output = parse(data.Payload);
336                if (!output.changed) {
337                  alert($t('basicError'));
338               } else {
339                  alert($t('passwordChangedSuccess'));
340            	  loginRequired();
341          }
342        }
343      });
344        }
345      }
346    });
347  }
348}
349
350function choosePassword() {
351	resetPassword(function(){
352		var sqs = new AWS.SQS();
353		var datas = {
354				salon_id: salon_id,
355				token: findGetParameter('lost'),
356				email: findGetParameter('email'),
357				rgpd: $('#inputRgpd').is(':checked'),
358		}
359		var params = {
360			MessageBody: JSON.stringify(datas),
361			QueueUrl: 'https://sqs.' + region + '.amazonaws.com/035751140488/choose_password_form'
362		};
363		
364		sqs.sendMessage(params, function(err, data) {
365			if (err){
366				console.log(err, err.stack);
367			}else {
368				console.log(data);
369				loginRequired();
370			}
371		});
372	});
373}
374
375function login() {
376  var email = document.getElementById('inputIdentifiant');
377  var password = document.getElementById('inputPassword');
378
379  if (email.value == null || email.value == '') {
380    alert($t('emailRequired'));
381  } else if (password.value == null || password.value == '') {
382    alert($t('passwordRequired'))
383  } else {
384    var input = {
385        email: email.value,
386        password: password.value
387    };
388
389    var functionName = salon_id + 'LambdAuthLogin';
390    var lambda = new AWS.Lambda();
391    lambda.invoke({
392      FunctionName: functionName,
393      Payload: JSON.stringify(input)
394    }, function(err, data) {
395      if (data.FunctionError) console.log(data);
396      else {
397        var output = parse(data.Payload);
398        if (!output.login) {
399        	if( typeof customFailedLoginMsg !== "undefined" && customFailedLoginMsg ){
400        		alert(customFailedLoginMsg);
401        	}else{
402        		alert(output.errorMessage || $t('authFailed'));
403        	}
404        } else {
405          var connexion_message = getActivityLogParams('email_login', salon_i
405d, salon_name, 0, input.email);
406          sendSQSMessage(connexion_message, function() {
407            initCreds(output.identityId, output.token, true, input.email);
408          });
409        }
410      }
411    });
412  }
413}
414
415function getUser(email, fn) {
416  const lambda = new AWS.Lambda();
417  const functionName = salon_id + 'LambdAuthGetUser';
418
419  lambda.invoke({
420    FunctionName: functionName,
421    Payload: JSON.stringify({
422      'email': email
423    })
424  }, function(err, data) {
425    if (data.FunctionError) {
426      fn(data);
427    } else {
428      const user = parse(data.Payload).user;
429      fn(null, user);
430    }
431  });
432}
433
434function checkUrlCredsToLogin(){
435	var token = findGetParameter('token');
436	var identityId = findGetParameter('identityId');
437	var email = findGetParameter('email');
438	
439	if(token !== null && identityId !== null && email !== null){
440		initCreds(identityId, token, false, email);
441		
442		window.history.replaceState({}, $(document).attr('title'), window.location.origin + window.location.pathname);
443		return true;
444	}
445	
446	return false;
447}
448
449function checkLoginInfo() {
450  var creds = Cookies.get('cognito_creds');
451
452  if (creds) {
453    // Si déjà connecté, suppression des infos dans URL si présentes
454    var token = findGetParameter('token');
455	var identityId = findGetParameter('identityId');
456	var email = findGetParameter('email');
457	
458	if(token !== null && identityId !== null && email !== null){
459		window.history.replaceState({}, $(document).attr('title'), window.location.origin + window.location.pathname);
460	}
461    return true;
462  }
463
464  return checkUrlCredsToLogin();
465}
466
467function initCreds(identityId, token, reload, email) {
468  var creds = {
469    identityId: identityId,
470    token: token
471  };
472
473  creds = {
474    IdentityPoolId: idPoolId,
475    IdentityId: creds.identityId,
476    Logins: {
477      'cognito-identity.amazonaws.com': creds.token
478    }
479  };
480
481  AWS.config.credentials = new AWS.CognitoIdentityCredentials(creds);
482
483  window.dataLayer = window.dataLayer || [];
484
485  AWS.config.credentials.get(function() {
486    var date = new Date(AWS.config.credentials.expireTime);
487    Cookies.set(
488      'cognito_creds', creds, { expires: date }
489    );
490
491    const callback = (err, user) => {
492      if (err) {
493        console.error(err);
494        return;
495      }
496
497      connectedUserObj = user;
498
499      try {
500        if (salon_id == 11) {
501          dataLayer.push({
502            'id' : user.odoo_id.S || user.odoo_id.N,  // odoo_id peut parfois
503														// être un string,
504														// parfois un nombre
505            'region' : user.region.S,
506            'country' : user.country.S,
507            'pillar': user.pillar.S
508          });
509        }
510      } catch (error) {
511        console.error('Unable to save data to dataLayer (probably due to a missing field on the user [pillar, region or country])', error);
512      }
513
514      if (Cookies.get('cognito_creds')) {
515        if (reload) anonymousRequired();
516        else updateCreds();
517      }
518    };
519
520    if ([11, 19, 107, 703, 407].indexOf(Number(salon_id)) != -1) {
521      getUser(email, callback);
522    } else {
523      if (Cookies.get('cognito_creds')) {
524        if (reload) anonymousRequired();
525        else updateCreds();
526      }
527    }
528  });
529
530  dataLayer.push({
531     'event' : 'formSubmissionSuccess',
532     'Form Label' : 'connexion'
533  });
534}
535
536function updateCreds() {
537  var creds = Cookies.getJSON('cognito_creds');
538
539  AWS.config.credentials = new AWS.CognitoIdentityCredentials(creds);
540
541  if (creds) {
542    AWS.config.credentials.get(function(err) {
543      if (AWS.config.credentials.expired || err) {
544        Cookies.remove('cognito_creds');
545        localStorage.setItem("isVisited", true);
546        loginRequired();
547      } else {
548        var date = new Date(AWS.config.credentials.expireTime);
549        Cookies.set(
550          'cognito_creds', creds, { expires: date }
551        );
552
553        // Oddly, this does not work ! We should retry sometime
554        // id = AWS.config.credentials.accessKeyId;
555        // secret = AWS.config.credentials.secretAccessKey;
556
557        opts = {
558          endpoint: atsEndpoint,
559          id: id,
560          secret: secret
561        }
562
563        cognito_client = new AWS.CognitoSyncManager();
564        cognito_client.openOrCreateDataset('Infos', function(err, dataset) {
565          dataset.synchronize({
566            onSuccess: function(dataset, newRecords) {
567              dataset.getAllRecords(function(err, records) {
568                const recordsObj = {};
569                records.forEach(record => {
570                  recordsObj[record.key] = record.value;
571                });
572
573                // Var setup
574                f_name = recordsObj.first_name || recordsObj.name;
575                l_name = recordsObj.last_name;
576                const name = recordsObj.name || (f_name + ' ' + l_name);
577                const initials = (f_name[0]+l_name[0]).toUpperCase();
578                $('#user-name').text(name);
579
580                if (recordsObj.first_name) $('#inputPrenom').val(recordsObj.first_name);
581                if (recordsObj.last_name) $('#inputNom').val(recordsObj.last_name);
582
583                const standName = recordsObj.stand_name;
584                const email = recordsObj.email;
585                const photo = recordsObj.profile_pic;
586                guide_user = (recordsObj.guide === 'true')
587                odoo_id = recordsObj.odoo_id;
588
589                let chatName = name;
590                if (standName) chatName += ' ' + standName;
591                connectedUserName = name;
592                connectedUserEmail = connectedUserEmail2 = email;
593                $('#inputEmail').val(email);
594                Cookies.set('user_email', email);
595
596                myOwnPhoto = photo;
597                $('#profile-pic').attr('src', photo);
598                $('#profile-pic').attr('alt', initials);
599                
600                $('#imgModif').attr('src', photo);
601                $('#imgModif').attr('alt', initials);
602
603                // Connect to chat
604                connectionInit(opts, getTopics(), chatName, photo);
605
606                // Setup conferences
607//                setupConfs();
608
609                // Compute conf URL
610//                if (typeof prefix !== 'undefined') computeRenderedConf();
611
612                // Log stand entry
613                if (stand_id) {
614                  var stand_enter_message = getActivityLogParams('stand_enter', stand_id, stand_name, stand_id);
615                  sendSQSMessage(stand_enter_message);
616                }
617
618                // Init quizz
619                if (typeof(initQuizz) != "undefined") initQuizz();
620              });
621
622              // var chatName = false;
623              // var chatPhoto = false;
624
625              // dataset.get('stand_name', function(err, value) {
626              // var standName = value;
627
628              // dataset.get('name', function(err, value) {
629              // var name = value || '';
630
631              // f_name = value;
632              // l_name = '';
633
634              // if (!value) {
635              // dataset.get('first_name', function(err, value) {
636              // var first_name = value || '';
637
638              // f_name = value;
639
640              // dataset.get('last_name', function(err, value) {
641              // var last_name = value || '';
642
643              // l_name = value;
644
645              // $('#user-name').text(first_name + ' ' + last_name);
646
647              // $('#inputPrenom').val(first_name);
648              // $('#inputNom').val(last_name);
649              // chatName = first_name + ' ' + last_name;
650              // if (standName) chatName = chatName + ' ' + standName;
651              // connectedUserName = first_name + ' ' + last_name;
652
653              // if (chatName != false && chatPhoto != false && typeof
654				// connectedUserEmail !== 'undefined') {
655              // try {
656              // if (!client.isConnected())
657              // connect(opts, getTopics(), chatName, chatPhoto);
658              // } catch (err) {
659              // connect(opts, getTopics(), chatName, chatPhoto);
660              // }
661              // }
662                        
663              // dataset.get('email', function(err, value) {
664              // connectedUserEmail2 = value;
665
666              // if (typeof conferences !== 'undefined') {
667              // if (conferences.constructor === Array) {
668              // var separatedConfs = separateConfs(conferences);
669              // renderConferences(separatedConfs[0], separatedConfs[1]);
670              // }
671              // }
672              // });
673
674              // if (prefix) {
675              // dataset.get('email', function(err, value) {
676              // var mail = value;
677              // if (sso_key && sso_iv)
678              // livee_url = generateVisitorUrl(mail, first_name, last_name,
679				// mail + '@' + salon_id, prefix, sso_key, sso_iv);
680              // else if (youtube_url)
681              // livee_url = youtube_url;
682              // else
683              // livee_url = prefix;
684              // $('a.visio').attr('href', livee_url);
685              // });
686              // }
687              // });
688              // });
689              // } else {
690              // $('#user-name').text(name);
691              // chatName = name;
692              // if (standName) chatName = chatName + ' ' + standName;
693              // connectedUserName = name;
694
695              // if (chatName != false && chatPhoto != false && typeof
696				// connectedUserEmail !== 'undefined') {
697              // try {
698              // if (!client.isConnected())
699              // connect(opts, getTopics(), chatName, chatPhoto);
700              // } catch (err) {
701              // connect(opts, getTopics(), chatName, chatPhoto);
702              // }
703              // }
704                        
705              // dataset.get('email', function(err, value) {
706              // connectedUserEmail2 = value;
707
708              // if (typeof conferences !== 'undefined') {
709              // if (conferences.constructor === Array) {
710              // var separatedConfs = separateConfs(conferences);
711              // renderConferences(separatedConfs[0], separatedConfs[1]);
712              // }
713              // }
714              // });
715
716              // if (prefix) {
717              // dataset.get('email', function(err, value) {
718              // var mail = value;
719              // if (sso_key && sso_iv)
720              // livee_url = generateVisitorUrl(mail, name, '', mail + '@' +
721				// salon_id, prefix, sso_key, sso_iv);
722              // else if (youtube_url)
723              // livee_url = youtube_url;
724              // else
725              // livee_url = prefix;
726              // $('a.visio').attr('href', livee_url);
727              // });
728              // }
729              // }
730              // });
731              // });
732
733              // dataset.get('profile_pic', function(err, value) {
734              // $('#profile-pic').attr('src', value);
735              // $('#imgModif').attr('src', value);
736              // chatPhoto = value;
737              // myOwnPhoto = value;
738
739              // if (chatName != false && chatPhoto != false && typeof
740				// connectedUserEmail !== 'undefined') {
741              // try {
742              // if (!client.isConnected())
743              // connect(opts, getTopics(), chatName, chatPhoto);
744              // } catch (err) {
745              // connect(opts, getTopics(), chatName, chatPhoto);
746              // }
747              // }
748              // });
749
750              // dataset.get('email', function(err, value) {
751              // connectedUserEmail = value;
752              // Cookies.set('user_email', connectedUserEmail);
753              // $('#inputEmail').val(value);
754              // if (chatName != false && chatPhoto != false && typeof
755				// connectedUserEmail !== 'undefined') {
756              // try {
757              // if (!client.isConnected())
758              // connect(opts, getTopics(), chatName, chatPhoto);
759              // } catch (err) {
760              // connect(opts, getTopics(), chatName, chatPhoto);
761              // }
762              // }
763
764              // if (stand_id) {
765              // var stand_enter_message = getActivityLogParams('stand_enter',
766				// stand_id, stand_name, stand_id);
767              // sendSQSMessage(stand_enter_message);
768              // }
769
770              // // We need the user's mail to init the quizz
771              // if (typeof(initQuizz) != "undefined") initQuizz();
772              // });
773
774              // dataset.get('guide', function(err, value) {
775              // if (value)
776              // guide_user = (value === 'true');
777              // });
778
779              // dataset.get('odoo_id', function(err, value) {
780              // if (value)
781              // odoo_id = value;
782              // });
783            }, onConflict: function(dataset, conflicts, callback) {
784              var resolved = [];
785              for (var i=0; i < conflicts.length; i++) {
786                resolved.push(conflicts[i].resolveWithRemoteRecord());
787              }
788              dataset.resolve(resolved, function() {
789                  return callback(true);
790              });
791            }
792          });
793        });
794      }
795    });
796  } else {
797    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
798        IdentityPoolId: idPoolId
799    });
800  }
801}
802
803function signOut() {
804  Cookies.remove('cognito_creds');
805  localStorage.setItem("isVisited", false);
806  tSignOut();
807}

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.