PageSourceSearch

https://unicore.one/register/js/modal.js?v=n_dqO5olyurtljQcklcXAlftQV1bjlm6L1uFLIl6_HE

js unicore.one collected 2026-09-24 11:02:06 UTC 7,899 bytes, 272 lines download raw bytes

1const _msg = window.registerLoc || {};
2
3new Vue({
4  el: "#registration-modal-content",
5  data: {
6    loading: false,
7    checking: false,
8    formError: null,
9    activeStepId: 0,
10    Role: "ORGANIZER",
11    legalEntityTypeList: [],
12
13    // Существующий аккаунт (проверяется на шаге 1)
14    existingAccount: false,
15    existingCompany: false,
16
17    // Step 1
18    RegistrationType: null,
19    Region: null,
20    FullName: null,
21    Email: null,
22    Password: null,
23    ConfirmPassword: null,
24    PhoneNumber: null,
25    IsHasReferralCode: false,
26    ReferralCode: null,
27
28    // Step 2
29    LegalEntityType: null,
30    Title: null,
31    Idn: null,
32    Uin: null,
33    AddressStr: null,
34    FactAddressStr: null,
35    IsSameAsJurAddress: false,
36
37    // Step 3
38    Languages: [],
39    AcceptTermConditions: false,
40  },
41  created() {
42    // 1. берём промокод из URL
43    const params = new URLSearchParams(window.location.search);
44    const promo = params.get("promocode");
45
46    if (promo) {
47      sessionStorage.setItem("promocode", promo);
48    }
49
50    // 2. берём промокод из sessionStorage
51    const savedPromo = sessionStorage.getItem("promocode");
52    if (savedPromo) {
53      this.ReferralCode = savedPromo;
54      this.IsHasReferralCode = true;
55    }
56
57    // 3. если пришли по реф-ссылке — авто-открываем модал
58    if (promo) {
59      $(function () {
60        $("#register-modal").modal("show");
61      });
62    }
63  },
64  computed: {
65    CityId() {
66      if (!this.Region) return null;
67      const regionId = this.Region.split("_")[0];
68      return parseInt(regionId);
69    },
70    CountryId() {
71      if (!this.Region) return null;
72      const regionId = this.Region.split("_")[2];
73      return parseInt(regionId);
74    },
75    CoverageType() {
76      if (!this.Region) return null;
77      const coverageType = this.Region.split("_")[4];
78      return coverageType;
79    },
80  },
81  watch: {
82    Role: {
83      handler(newRole) {
84        if (newRole === 'ORGANIZER') {
85          this.RegistrationType = null;
86          return;
87        }
88
89        this.RegistrationType = 2;
90      },
91      immediate: true,
92    },
93    CountryId: {
94      handler() {
95        this.loadLegalEntityTypeList();
96      },
97    },
98    Email() {
99      this.resetExistingAccount();
100    },
101    Password() {
102      this.resetExistingAccount();
103    },
104  },
105  methods: {
106    selectRole: function (role) {
107      if (this.loading) return;
108      this.formError = null;
109      this.Role = role;
110      this.activeStepId = 1;
111    },
112    backToStep: function (step) {
113      if (this.loading) return;
114      if (step < this.activeStepId) {
115        this.formError = null;
116        this.activeStepId = step;
117      }
118    },
119    resetExistingAccount: function () {
120      this.formError = null;
121      this.existingAccount = false;
122      this.existingCompany = false;
123    },
124    checkRegistration: async function (form) {
125      const token = form.querySelector('input[name="__RequestVerificationToken"]');
126      const url = form.action.replace(/\/Register(\?|$)/i, "/CheckRegistration$1");
127
128      const body = new FormData();
129      body.append("email", this.Email || "");
130      body.append("password", this.Password || "");
131      body.append("role", this.Role || "");
132      if (token) body.append("__RequestVerificationToken", token.value);
133
134      this.checking = true;
135      try {
136        const response = await fetch(url, {
137          method: "POST",
138          headers: { "X-Requested-With": "XMLHttpRequest" },
139          body,
140        });
141        return await response.json();
142      } catch (err) {
143        console.error("CheckRegistration error:", err);
144        this.formError = _msg.checkFailed || `${_msg.networkError} ${_msg.networkErrorRetry}`;
145        return null;
146      } finally {
147        this.checking = false;
148      }
149    },
150    loadLegalEntityTypeList: async function () {
151      const v = this;
152      const url = `/api/dictionary/legal-entity-types?countryId=${v.CountryId}`;
153
154      try {
155        const response = await fetch(url);
156        const result = await response.json();
157
158        v.legalEntityTypeList = result;
159      } catch (err) {
160        console.error("Error loading events:", err);
161      }
162    },
163    submit: async function () {
164      const form = document.getElementById("registration-form");
165      this.formError = null;
166
167      // STEP 0 — пароли
168      if (this.activeStepId === 1) {
169        if (this.Password !== this.ConfirmPassword) {
170          this.formError = _msg.passwordsMismatch;
171          return;
172        }
173      }
174
175      // STEP 2 — языки (только для не-клиентов)
176      if (this.activeStepId === 2 && this.Role !== 'CUSTOMER') {
177        if (!this.Languages.length) {
178          this.formError = _msg.noLanguages;
179          return;
180        }
181      }
182
183      // Нативная HTML5 валидация
184      if (!form.checkValidity()) {
185        form.reportValidity();
186        return;
187      }
188
189      // ШАГ 1 — проверяем, есть ли уже аккаунт с таким email
190      if (this.activeStepId === 1) {
191        const check = await this.checkRegistration(form);
192        if (!check) return; // ошибка сети — сообщение уже показано
193
194        if (!check.ok) {
195          this.formError = check.message || `${_msg.registrationError})`;
196          return;
197        }
198
199        this.existingAccount = !!check.exists;
200        // Существующий аккаунт с компанией — данные компании повторно не нужны
201        this.existingCompany = !!check.exists && !check.needsCompanyData;
202      }
203
204      // ЕСЛИ ЭТО ПОСЛЕДНИЙ ШАГ — ОТПРАВЛЯЕМ ФОРМУ
205      const isLastStep = this.activeStepId === 2 || (this.activeStepId === 1 && this.Role === 'CUSTOMER');
206      if (isLastStep) {
207        if (this.loading) return;
208
209        this.loading = true;
210
211        try {
212          const response = await fetch(form.action, {
213            method: "POST",
214            body: new FormData(form),
215            headers: {
216              "X-Requested-With": "XMLHttpRequest",
217            },
218          });
219
220          if (!response.ok) {
221            let message = `${_msg.registrationError} ${response.status})`;
222            try {
223              const contentType = response.headers.get("Content-Type") || "";
224              if (contentType.indexOf("application/json") !== -1) {
225                const error = await response.json();
226                if (error && error.message) {
227                  message = error.message;
228                }
229              } else {
230                const text = await response.text();
231                if (text) {
232                  message += `: ${text.substring(0, 300)}`;
233                }
234              }
235            } catch (e) {
236              // ignore parse/reading errors and keep fallback message
237            }
238
239            this.formError = message;
240            return;
241          }
242
243          const contentType = response.headers.get("Content-Type") || "";
244          if (contentType.indexOf("application/json") !== -1) {
245            const result = await response.json();
246            if (result && result.redirectUrl) {
247              window.location.href = result.redirectUrl;
248              return;
249            }
250
251            window.location.reload();
252          } else {
253            if (response.url) {
254              window.location.href = response.url;
255            } else {
256              window.location.reload();
257            }
258          }
259        } catch (err) {
260          this.formError = `${_msg.networkError} ${err && err.message ? err.message : _msg.networkErrorRetry}`;
261        } finally {
262          this.loading = false;
263        }
264
265        return;
266      }
267
268      // ИНАЧЕ — просто следующий шаг
269      this.activeStepId++;
270    },
271  },
272});

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.