1(function () { 2 'use strict'; 3 4 var root = null; 5 var captchaWidgetId = null; 6 var captchaResolve = null; 7 8 window.profitkitAuthCaptchaOnload = function () { 9 var config = window.ProfitkitUnifiedAuthConfig || {}; 10 var container = document.querySelector('[data-auth-captcha]'); 11 12 if (!container || !window.smartCaptcha || !config.captchaSiteKey) { 13 return; 14 } 15 16 captchaWidgetId = window.smartCaptcha.render(container, { 17 sitekey: config.captchaSiteKey, 18 invisible: true, 19 callback: function (token) { 20 if (captchaResolve) { 21 captchaResolve(token); 22 captchaResolve = null; 23 } 24 } 25 }); 26 }; 27 28 function showMessage(text, type) { 29 var box = root.querySelector('[data-auth-message]'); 30 if (!box) { 31 return; 32 } 33 34 box.textContent = text || ''; 35 box.className = 'unified-auth__message' + (type ? ' unified-auth__message--' + type : ''); 36 box.hidden = !text; 37 } 38 39 function setLoading(button, isLoading) { 40 if (!button) { 41 return; 42 } 43 44 button.disabled = !!isLoading; 45 if (isLoading) { 46 button.setAttribute('data-old-text', button.textContent); 47 button.textContent = 'ÐодождиÑе...'; 48 } else if (button.getAttribute('data-old-text')) { 49 button.textContent = button.getAttribute('data-old-text'); 50 button.removeAttribute('data-old-text'); 51 } 52 } 53 54 function getCaptchaToken() { 55 var config = window.ProfitkitUnifiedAuthConfig || {}; 56 57 if (!config.useCaptcha) { 58 return Promise.resolve(''); 59 } 60 61 if (!window.smartCaptcha || captchaWidgetId === null) { 62 return Promise.reject(new Error('ÐапÑа не загÑÑжена.')); 63 } 64 65 return new Promise(function (resolve) { 66 captchaResolve = resolve; 67 window.smartCaptcha.execute(captchaWidgetId); 68 }); 69 } 70 71 function resetCaptcha() { 72 if (window.smartCaptcha && captchaWidgetId !== null) { 73 window.smartCaptcha.reset(captchaWidgetId); 74 } 75 } 76 77 function runAction(action, data) { 78 var config = window.ProfitkitUnifiedAuthConfig || {}; 79 data = data || {}; 80 data.sessid = BX.bitrix_sessid(); 81 82 return BX.ajax.runComponentAction(config.component, action, { 83 mode: 'class', 84 signedParameters: config.signedParameters, 85 data: data 86 }); 87 } 88 89 function getErrorMessage(response, fallback) { 90 if (response && response.errors && response.errors.length && response.errors[0].message) { 91 return response.errors[0].message; 92 } 93 94 if (response && response.message) { 95 return response.message; 96 } 97 98 return fallback; 99 } 100 101 function setChannel(channel) { 102 var form = root.querySelector('[data-auth-form]'); 103 var login = root.querySelector('[data-auth-login]'); 104 var label = root.querySelector('[data-auth-login-label]'); 105 var requestButton = root.querySelector('[data-auth-request]'); 106 var emailSwitcher = root.querySelector('[data-auth-switch="email"]'); 107 var pushSwitcher = root.querySelector('[data-auth-switch="push"]'); 108 109 form.setAttribute('data-channel', channel); 110 form.setAttribute('data-auth-current-mode', channel); 111 112 if (channel === 'email') { 113 label.textContent = 'Email'; 114 login.type = 'email'; 115 login.inputMode = 'email'; 116 login.autocomplete = 'email'; 117 login.placeholder = '[email protected]'; 118 requestButton.textContent = 'ÐолÑÑиÑÑ ÐºÐ¾Ð´'; 119 if (emailSwitcher) { 120 emailSwitcher.textContent = 'ÐойÑи по ÑелеÑонÑ'; 121 emailSwitcher.setAttribute('data-auth-target', 'sms'); 122 } 123 if (pushSwitcher) { 124 pushSwitcher.textContent = 'ÐойÑи ÑеÑез пÑÑ'; 125 pushSwitcher.setAttribute('data-auth-target', 'push'); 126 } 127 if (window.jQuery && window.jQuery.fn && window.jQuery.fn.unmask) { 128 window.jQuery(login).unmask(); 129 } 130 } else { 131 label.textContent = 'ТелеÑон'; 132 login.type = 'tel'; 133 login.inputMode = 'tel'; 134 login.autocomplete = 'tel'; 135 login.placeholder = '+7 (___) ___-__-__'; 136 requestButton.textContent = channel === 'push' ? 'ÐÑпÑавиÑÑ push' : 'ÐолÑÑиÑÑ ÐºÐ¾Ð´'; 137 if (emailSwitcher) { 138 emailSwitcher.textContent = 'ÐойÑи по поÑÑе'; 139 emailSwitcher.setAttribute('data-auth-target', 'email'); 140 } 141 if (pushSwitcher) { 142 pushSwitcher.textContent = channel === 'push' ? 'ÐойÑи по SMS' : 'ÐойÑи ÑеÑез пÑÑ'; 143 pushSwitcher.setAttribute('data-auth-target', channel === 'push' ? 'sms' : 'push'); 144 } 145 applyPhoneMask(login); 146 } 147 148 login.value = ''; 149 login.focus(); 150 } 151 152 function applyPhoneMask(input) { 153 if (window.jQuery && window.jQuery.fn && window.jQuery.fn.mask) { 154 window.jQuery(input).mask('+7 (999) 999-99-99'); 155 } 156 } 157 158 function formatPhone(value) { 159 var digits = String(value || '').replace(/\D/g, ''); 160 161 if (digits.length === 10 && digits.charAt(0) === '9') { 162 digits = '7' + digits; 163 } 164 if (digits.length === 11 && digits.charAt(0) === '8') { 165 digits = '7' + digits.slice(1); 166 } 167 if (digits.length !== 11 || digits.charAt(0) !== '7') { 168 return value || ''; 169 } 170 171 return '+7 (' + digits.slice(1, 4) + ') ' + digits.slice(4, 7) + '-' + digits.slice(7, 9) + '-' + digits.slice(9, 11); 172 } 173 174 function showCodeStep(data) { 175 var requestStep = root.querySelector('[data-auth-step="request"]');
176 var codeStep = root.querySelector('[data-auth-step="code"]'); 177 var contact = root.querySelector('[data-auth-contact]'); 178 var contactLabel = root.querySelector('[data-auth-contact-label]'); 179 var token = root.querySelector('[data-auth-token]'); 180 var codeInput = root.querySelector('[data-auth-code]'); 181 182 token.value = data.token || ''; 183 contact.textContent = data.maskedContact || ''; 184 contactLabel.textContent = data.channel === 'email' ? 'Ðод оÑпÑавлен на email' : (data.channel === 'push' ? 'Ðод оÑпÑавлен в push' : 'Ðод оÑпÑавлен в SMS'); 185 var pushNote = root.querySelector('[data-auth-push-note]'); 186 var noteText = root.querySelector('[data-auth-note-text]'); 187 if (pushNote) { 188 pushNote.hidden = data.channel !== 'push'; 189 } 190 if (noteText && data.channel === 'push') { 191 noteText.textContent = 'У Ð²Ð°Ñ ÑÑÑановлено пÑиложение MCBUY, код оÑпÑавлен в push-ÑообÑении.'; 192 } 193 requestStep.hidden = true; 194 codeStep.hidden = false; 195 codeInput.value = ''; 196 codeInput.focus(); 197 startTimer(parseInt(data.nextTime || 60, 10)); 198 } 199 200 function showRequestStep() { 201 root.querySelector('[data-auth-step="code"]').hidden = true; 202 root.querySelector('[data-auth-step="request"]').hidden = false; 203 root.querySelector('[data-auth-register]').hidden = true; 204 showMessage('', ''); 205 } 206 207 function showRegister(data) { 208 var register = root.querySelector('[data-auth-register]'); 209 var codeStep = root.querySelector('[data-auth-step="code"]'); 210 var phoneInput = register.querySelector('input[name="REGISTER[PERSONAL_PHONE]"]'); 211 var emailInput = register.querySelector('input[name="REGISTER[EMAIL]"]'); 212 var phoneText = register.querySelector('[data-register-confirmed-phone]'); 213 var emailText = register.querySelector('[data-register-confirmed-email]'); 214 215 codeStep.hidden = true; 216 register.hidden = false; 217 218 if (data.phone && phoneInput) { 219 phoneInput.value = data.phone; 220 } 221 if (data.email && emailInput) { 222 emailInput.value = data.email; 223 } 224 if (phoneText && data.phone) { 225 phoneText.textContent = formatPhone(data.phone); 226 } 227 if (emailText && data.email) { 228 emailText.textContent = data.email; 229 } 230 } 231 232 var timerId = null; 233 function startTimer(seconds) { 234 var timer = root.querySelector('[data-auth-resend-timer]'); 235 var button = root.querySelector('[data-auth-resend]'); 236 var left = seconds; 237 238 clearInterval(timerId); 239 button.hidden = true; 240 timer.hidden = false; 241 timer.textContent = 'ÐапÑоÑиÑÑ ÐºÐ¾Ð´ повÑоÑно можно ÑеÑез ' + left + ' Ñек.'; 242 243 timerId = setInterval(function () { 244 left -= 1; 245 if (left <= 0) { 246 clearInterval(timerId); 247 timer.hidden = true; 248 button.hidden = false; 249 return; 250 } 251 timer.textContent = 'ÐапÑоÑиÑÑ ÐºÐ¾Ð´ повÑоÑно можно ÑеÑез ' + left + ' Ñек.'; 252 }, 1000); 253 } 254 255 function init() { 256 root = document.querySelector('[data-profitkit-auth]'); 257 if (!root || !window.BX || !BX.ajax) { 258 return; 259 } 260 261 var form = root.querySelector('[data-auth-form]'); 262 if (!form) { 263 return; 264 } 265 266 var login = root.querySelector('[data-auth-login]'); 267 var code = root.querySelector('[data-auth-code]'); 268 applyPhoneMask(login); 269 if (window.jQuery && window.jQuery.fn && window.jQuery.fn.mask) { 270 window.jQuery(code).mask('9999'); 271 } 272 273 root.querySelectorAll('[data-channel-button]').forEach(function (button) { 274 button.addEventListener('click', function () { 275 setChannel(button.getAttribute('data-auth-target') || button.getAttribute('data-channel-button')); 276 }); 277 }); 278 279 form.addEventListener('submit', function (event) { 280 event.preventDefault(); 281 282 var agreement = root.querySelector('[data-auth-agreement]'); 283 var submit = root.querySelector('[data-auth-request]'); 284 var channel = form.getAttribute('data-channel') || 'sms'; 285 286 if (agreement && !agreement.checked) { 287 agreement.reportValidity(); 288 return; 289 } 290 291 showMessage('', '');
292 setLoading(submit, true); 293 294 getCaptchaToken().then(function (captchaToken) { 295 runAction('requestCode', { 296 channel: channel, 297 login: login.value, 298 captchaToken: captchaToken 299 }).then(function (response) { 300 var data = response.data || {}; 301 resetCaptcha(); 302 setLoading(submit, false); 303 if (data.status !== 'ok') { 304 showMessage(data.message || 'Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ ÐºÐ¾Ð´.', 'error'); 305 return; 306 } 307 if (data.notice) { 308 showMessage(data.notice, 'notice'); 309 } 310 showCodeStep(data); 311 }, function (response) { 312 resetCaptcha(); 313 setLoading(submit, false); 314 showMessage(getErrorMessage(response, 'Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ ÐºÐ¾Ð´.'), 'error'); 315 }); 316 }, function (error) { 317 resetCaptcha(); 318 setLoading(submit, false); 319 showMessage(error.message || 'Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ ÐºÐ¾Ð´.', 'error'); 320 }); 321 }); 322 323 root.querySelector('[data-auth-confirm]').addEventListener('click', function () { 324 var button = this; 325 var token = root.querySelector('[data-auth-token]').value; 326 327 showMessage('', ''); 328 setLoading(button, true); 329 330 runAction('confirmCode', { 331 token: token, 332 code: code.value 333 }).then(function (response) { 334 var data = response.data || {}; 335 setLoading(button, false); 336 if (data.status !== 'ok') { 337 showMessage(data.message || 'ÐевеÑнÑй код.', 'error'); 338 return; 339 } 340 if (data.state === 'authorized') { 341 window.location.href = data.redirect || '/personal/'; 342 return; 343 } 344 if (data.state === 'register') { 345 showRegister(data); 346 } 347 }, function (response) { 348 setLoading(button, false); 349 showMessage(getErrorMessage(response, 'Ðе ÑдалоÑÑ Ð¿ÑовеÑиÑÑ ÐºÐ¾Ð´.'), 'error'); 350 }); 351 }); 352 353 root.querySelector('[data-auth-change]').addEventListener('click', showRequestStep); 354 355 root.querySelector('[data-auth-resend]').addEventListener('click', function () { 356 var button = this; 357 var token = root.querySelector('[data-auth-token]').value; 358 setLoading(button, true); 359 360 runAction('resendCode', {token: token}) 361 .then(function (response) { 362 var data = response.data || {}; 363 setLoading(button, false); 364 if (data.status !== 'ok') { 365 showMessage(data.message || 'Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ ÐºÐ¾Ð´.', 'error'); 366 return; 367 } 368 if (data.notice) { 369 showMessage(data.notice, 'notice'); 370 } 371 showCodeStep(data); 372 }, function (response) { 373 setLoading(button, false); 374 showMessage(getErrorMessage(response, 'Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ ÐºÐ¾Ð´.'), 'error'); 375 }); 376 }); 377 378 root.addEventListener('click', function (event) { 379 if (event.target.matches('[data-register-back]')) { 380 event.preventDefault(); 381 showRequestStep(); 382 } 383 }); 384 } 385 386 if (document.readyState === 'loading') { 387 document.addEventListener('DOMContentLoaded', init); 388 } else { 389 init(); 390 } 391})();
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.