PageSourceSearch

https://ioctopus.online/wp-content/plugins/app/person/person.site.js?ver=v1722752945

js ioctopus.online collected 2026-10-04 22:22:08 UTC 15,167 bytes, 682 lines download raw bytes

1{
2  wdpro.person = {};
3
4  let initGoogleAuthIfNeed;
5
6
7  const saveAuthCookiesFromRes = res => {
8    // if (res['auth_id']) {
9    //   wdpro.setCookie('auth_id', res['auth_id']);
10    //   wdpro.setCookie('auth_key', res['auth_key']);
11    // }
12  };
13
14
15  const googleButtonParams = {
16    // theme: "outline",
17    theme: "filled_blue",
18    size: "large",
19  };
20
21  
22  wdpro.ready($ => {
23
24    let registerForm, loginForm, twoAuthForm;
25    let googleInited = false;
26    let vkLoginOptions;
27    let yaLoginInit;
28
29
30    // Yandex Auth
31    if (wdpro.YA_AUTH) {
32      yaLoginInit = $container => {
33        const button = templates.person.yaAuthButton({
34          homeUrl: wdpro.homeUrl(),
35          url: wdpro.YA_AUTH_URL,
36        });
37
38        $container.empty().append(button);
39      }
40
41      yaLoginInit($('#js-login-ya-on-page').show())
42    }
43
44
45    // VK Login
46    // if (wdpro.VK_AUTH) {
47    //   vkLoginOptions = {
48    //     onAuth: data => {
49    //       wdpro.ajax('auth-by-vk', data, res => {
50    //         const $buttons = $('#js-login-vk-on-page').add('.js-google');
51    //         $buttons.loading();
52    //       });
53    //     },
54    //   };
55    //
56    //   VK.Widgets.Auth('js-login-vk-on-page', vkLoginOptions);
57    // }
58
59
60    // Google Login
61    if (wdpro.GOOGLE_AUTH) {
62      // Google Check
63      const googleAuthCallback = data => {
64
65        const $buttons = $('#js-google-on-page').add('.js-google');
66
67        $buttons.loading();
68
69        wdpro.ajax(
70          {
71            action: 'auth-by-google',
72          },
73
74          {
75            token: data.credential,
76          },
77
78          res => {
79
80            saveAuthCookiesFromRes(res);
81
82            wdpro.yandexMetrikaGoal('register--google');
83
84            if (res['url']) {
85              window.location = res['url'];
86              return;
87            }
88
89            if (res['error']) {
90              alert(res['error']);
91            }
92
93            $buttons.loadingStop();
94          }
95        );
96      };
97
98
99      // Google Init
100      initGoogleAuthIfNeed = callback => {
101
102        const check = () => {
103          if (window.google) {
104            if (googleInited) {
105              callback();
106              return;
107            }
108            googleInited = true;
109
110            google.accounts.id.initialize({
111              client_id: "191507607169-pjfs93p6275qg211sltes34hu4afvm2s.apps.googleusercontent.com",
112              callback: googleAuthCallback
113            });
114            callback();
115            return;
116          }
117
118          setTimeout(check, 300);
119        }
120
121        check();
122      };
123
124
125      // Google On Page
126      $('#js-google-on-page').show().each(function () {
127        initGoogleAuthIfNeed(() => {
128          google.accounts.id.renderButton(
129            $(this).get(0),
130            googleButtonParams
131          );
132        });
133      });
134    }
135
136    
137
138
139    // Open Settings Data Form
140    wdpro.person.openSettingsDataPage = () => {
141
142      new wdpro.dialogs.Dialog({
143        url: wdpro.ajaxUrl({
144          'action': 'personSettingsDataPage',
145        }),
146        cssClass: 'dialog--full-size',
147        bodyClass: 'dialog--full-size--opened',
148        maxWidth: null,
149        title: 'Personal data',
150      });
151    };
152
153    // Open Settings Auth Form
154    wdpro.person.openSettingsAuthPage = () => {
155
156      new wdpro.dialogs.Dialog({
157        url: wdpro.ajaxUrl({
158          'action': 'personSettingsAuthPage',
159        }),
160        cssClass: 'dialog--full-size',
161        bodyClass: 'dialog--full-size--opened',
162        maxWidth: null,
163        title: 'Authorization settings',
164      });
165    };
166
167
168    // Open Register Form
169    wdpro.person.openAuthForm = params => {
170
171      if (wdpro.isLogged) {
172        new wdpro.dialogs.Dialog({
173          content: templates.person.youAreAlreadyLogged({
174            lang: wdpro.lang(),
175          }),
176          substrate: true,
177          // title: 'Start',
178          // maxWidth: null,
179          // cssClass: 'dialog--full-size',
180        });
181        return;
182      }
183
184      let $page = $(templates.person.startPage({
185        lang: wdpro.lang(),
186        homeUrl: wdpro.homeUrl(),
187        showDemo: wdpro.demoInRegisterForm,
188        demoButtonText: wdpro.translate({
189          // IOtranslate
190          '': 'Demo',
191          'fr': 'Démonstration',
192          'es': 'Demostración',
193          'pt': 'Demonstração',
194          'ua': 'Демонстрація',
195          'ch': '演示',
196          'jp': 'デモ',
197          'ru': 'Демо',
198        }),
199        demoText: wdpro.translate({
200          // IOtranslate
201          '': 'without registration',
202          'fr': 'sans inscription',
203          'es': 'sin registro',
204          'pt': 'sem registro',
205          'ua': 'без реєстрації',
206          'ch': '无需注册',
207          'jp': '登録なし',
208          'ru': 'без регистрации',
209        }),
210      }));
211
212
213      // Google
214      if (wdpro.GOOGLE_AUTH) {
215        initGoogleAuthIfNeed(() => {
216          const $google = $page.find('.js-google')
217          $google.removeClass('hid')
218          console.log('$google', $google)
219          google.accounts.id.renderButton(
220            $google.get(0),
221            googleButtonParams
222          );
223          // google.accounts.id.prompt();
224        });
225      }
226
227
228      // VK Login
229      // if (wdpro.VK_AUTH) {
230      //   VK.Widgets.Auth('js-login-vk', vkLoginOptions);
231      // }
232
233
234      // YA Login
235      console.log('wdpro.YA_AUTH', wdpro.YA_AUTH)
236      if (wdpro.YA_AUTH) {
237        const $ya = $page.find('#js-login-ya')
238        console.log('$ya', $ya)
239        $ya.removeClass('hid')
240        yaLoginInit($ya);
241      }
242      
243
244
245      // Tabs
246      $page.find('.js-tabs').tabsBlock(params);
247
248      wdpro.order(
249
250        // Register Form
251        next => {
252          getRegisterForm().getHtml($html => {
253            $page.find('.js-register-form--container').append($html);
254            next();
255          });
256        },
257
258        // Login Form
259        next => {
260          getLoginForm().getHtml($html => {
261            $page.find('.js-login-form--container').append($html);
262            next();
263          });
264        },
265
266        // Dialog
267        () => {
268          new wdpro.dialogs.Dialog({
269            content: $page,
270            //title: 'Start',
271            maxWidth: null,
272            cssClass: 'dialog--full-size',
273            bodyClass: 'dialog--full-size--opened',
274          });
275        }
276      );
277    };
278
279
280    const getRegisterForm = () => {
281
282      if (false && registerForm) return registerForm;
283
284      registerForm = new RegisterForm();
285      console.log('registerForm', registerForm)
286      return registerForm;
287    };
288
289
290    const getLoginForm = () => {
291      loginForm = new LoginForm();
292      return loginForm;
293    };
294
295
296    const getTwoAuthForm = () => {
297      twoAuthForm = new TwoAuthForm()
298      return twoAuthForm
299    }
300
301
302    $('#js-auth-form').each(function () {
303
304      const $container = $(this);
305      getLoginForm().getHtml($html => {
306        $container.append($html);
307      });
308    });
309
310
311    $('#js-two-auth-form').each(function () {
312
313      const $container = $(this);
314      getTwoAuthForm().getHtml($html => {
315        $container.append($html);
316      });
317    });
318
319
320    $('#js-register-form').each(function () {
321
322      const $container = $(this);
323      getRegisterForm().getHtml($html => {
324        $container.append($html);
325      });
326    });
327
328
329
330
331    wdpro.forms.onForm('settings-auth-form', form => {
332      setTimeout(() => {
333        wdpro.passwordForm(form.jForm)
334        wdpro.twoAuthForm(form)
335      })
336    })
337
338
339    wdpro.forms.onForm('two-auth-required-form', form => {
340      setTimeout(() => {
341        wdpro.twoAuthForm(form)
342      })
343    })
344
345
346    wdpro.forms.onForm('reset-password-form', form => {
347      setTimeout(() => {
348        wdpro.passwordForm(form.jForm)
349      })
350    })
351
352
353    wdpro.forms.onForm('completion', form => {
354      console.error('completion')
355      setTimeout(() => {
356        wdpro.passwordForm(form.jForm)
357      })
358    })
359
360  });
361
362
363
364  // Promocode Input
365  const promocodeInputInit = form => {
366    let promocodeValid = true;
367    let element = form.elements.promocode;
368    if (!element) return;
369    let $input = element.field;
370    let $result = element.html.find('.js-result');
371    let loading = false;
372    let lastVal = '';
373
374
375    const updateFromServer = wdpro.debounce(() => {
376      let val = $input.val();
377      if (val) {
378
379        wdpro.ajax(
380          {
381            action: 'register_promocode_check',
382            promocode: val,
383          },
384          res => {
385            $result.loadingStop();
386            loading = false;
387
388            if (res.success) {
389
390              let message = `Success. You get a 50% discount.`;
391
392              // Deadline
393              message += `<BR>You can activate the discount within 1 year.`;
394
395              $result.html(message)
396                .addClass('promocode--success');
397              form.html.removeClass('form-disabled');
398              promocodeValid = true;
399            }
400            else {
401              // IOtranslate
402              $result.html(wdpro.translate({
403                '': 'This is an invalid promo code.',
404                'fr': 'Ce code promo n\'est pas valide.',
405                'es': 'Este código de promoción no es válido.',
406                'pt': 'Esse código promocional é inválido.',
407                'ua': 'Це недійсний промо-код.',
408                'ch': '此促销代碼無效。',
409                'jp': 'このプロモーションコードは無効です。',
410                'ru': 'Это не верный промокод',
411              }))
412                .removeClass('promocode--success');
413            }
414          }
415        )
416      }
417    }, 500);
418
419
420    const updatePromocode = () => {
421      let val = $input.val();
422      if (val === lastVal) return;
423      lastVal = val;
424
425      $result.empty();
426
427      if (val) {
428        promocodeValid = false;
429      }
430
431      else {
432        promocodeValid = true;
433      }
434
435      if (promocodeValid) {
436        form.html.removeClass('form-disabled');
437      }
438      else {
439        form.html.addClass('form-disabled');
440      }
441
442      if (!loading && val) {
443        loading = true;
444        $result.loading();
445      }
446
447      updateFromServer();
448
449    }
450    $input.on('keyup keydown change', updatePromocode);
451
452    form.addValidator((data, callback) => {
453      if (promocodeValid) {
454        callback();
455      }
456      else {
457        callback({
458          error: 'Promocode is not valid',
459          stop: true,
460        });
461      }
462    });
463
464  };
465
466
467  wdpro.forms.onForm('additional_info_form', form => {
468    setTimeout(() => {
469      promocodeInputInit(form);
470    })
471  })
472
473  
474  // Register Form
475  class RegisterForm extends wdpro.forms.Form {
476
477    initElements() {
478
479      console.log('wdpro.registerFormData', wdpro.registerFormData)
480
481      this.initParams(wdpro.registerFormData);
482
483      // Promocode
484      setTimeout(() => promocodeInputInit(this));
485
486
487      this.addValidator((data, callback) => {
488        if (data.registerPass1 !== data.registerPass2) {
489          callback({
490            // IOtranslate
491            error: wdpro.translate({
492              '': 'Passwords don\'t match',
493              'fr': 'Les mots de passe ne correspondent pas',
494              'es': 'Las contraseñas no coinciden',
495              'pt': 'As senhas não correspondem',
496              'ua': 'Паролі не співпадають',
497              'ch': '密碼不匹配',
498              'jp': 'パスワードが一致しません',
499              'ru': 'Пароли не совпадают',
500            }),
501            prepend: true,
502          });
503        }
504
505        callback();
506      });
507
508      
509      // Metrika
510      wdpro.yandexMetrikaGoal('register--form--open');
511      this.on('trySend', () => {
512        wdpro.yandexMetrikaGoal('register--form--try-to-send');
513      });
514
515
516      // Ajax
517      this.ajax(data => {
518
519        wdpro.ajax(
520          'register_form_post',
521          data,
522
523          res => {
524
525            // Error
526            if (res['error']) {
527              this.showErrorMessage(res['error']);
528              this.loadingStop();
529              return;
530            }
531
532            // Ok
533            if (res['ok']) {
534              if (res['html']) {
535                this.dialog().setContent(res['html']);
536              }
537              
538              wdpro.yandexMetrikaGoal('register--form--sended');
539
540              saveAuthCookiesFromRes(res);
541
542              // Сохраняем текущую страницу в localstorage, чтобы после регистрации можно было вернуться на эту страницу
543              if (res['openSharedAfterRegistration']) {
544                window.localStorage.setItem('afterRegisterUrl', window.location.href)
545              }
546
547              if (res['reload']) {
548                setTimeout(() => {
549                  window.location = window.location;
550                }, 1000);
551              }
552
553              if (res['url']) {
554                setTimeout(() => {
555                  window.location = res['url'];
556                }, 1000);
557              }
558            }
559          }
560        )
561      });
562    }
563
564
565    initJForm() {
566      super.initJForm()
567
568      setTimeout(() => {
569        wdpro.passwordForm(this.jForm)
570      })
571    }
572
573  }
574
575
576  // Login Form
577  class LoginForm extends wdpro.forms.Form {
578
579    getNewForm() {
580      return new LoginForm()
581    }
582
583    
584    initElements () {
585
586      if (!this.groups.length) {
587        this.initParams(wdpro.loginFormData);
588      }
589
590
591      // Ajax
592      this.ajax(async data => {
593        this.hideMessage();
594
595        wdpro.ajax(
596          'login_form_post',
597          data,
598
599          res => {
600
601            let form = this
602
603            form.hideMessage()
604
605            // Новая форма
606            if (res['form']) {
607              this.loadingStop();
608              form = this.replace(res['form'])
609            }
610
611            // Error
612            console.log('login res', res)
613            if (res['error']) {
614              form.loadingStop();
615              form.showErrorMessage(res['error']);
616              return;
617            }
618
619            // Ok
620            if (res['ok']) {
621              saveAuthCookiesFromRes(res);
622              window.location = window.location;
623            }
624          }
625        );
626      });
627    }
628
629
630  }
631
632
633  // Two Auth Form
634  class TwoAuthForm extends wdpro.forms.Form {
635
636    initElements() {
637      this.initParams(wdpro.twoAuthFormData)
638
639      // Ajax
640      this.ajax(async data => {
641        this.hideMessage()
642
643        wdpro.ajax(
644          'two_auth_post',
645          data,
646          res => {
647
648            // Error
649            if (res['error']) {
650              this.loadingStop();
651
652              if (res['error']['text']) {
653                this.showErrorMessage(res['error']['text']);
654              }
655              else {
656                this.showErrorMessage(res['error']);
657              }
658              return;
659            }
660
661
662            // Ok
663            if (res['ok']) {
664              // saveAuthCookiesFromRes(res);
665              // wdpro.setCookie('two_auth_key', res['two_auth_key']);
666              window.location = window.location;
667            }
668          }
669        )
670      })
671    }
672
673  }
674
675}
676
677
678
679
680
681
682

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.