PageSourceSearch

https://csk66.ru/local/templates/main/js/password-recovery.js

js csk66.ru collected 2026-10-07 15:46:45 UTC 4,334 bytes, 123 lines download raw bytes

1/**
2 * Обработка формы восстановления пароля
3 */
4document.addEventListener('DOMContentLoaded', function() {
5    const recoveryForm = document.querySelector('.js-recovery-form');
6    const resendButton = document.querySelector('.js-recovery-form-resend');
7    const submitButton = document.querySelector('.js-recovery-form-submit');
8    const emailInput = document.querySelector('.js-recovery-form-email');
9    const messageElement = document.querySelector('.modal-recovery-form__message');
10    const mainTextElement = document.querySelector('.modal-recovery-form__main-text');
11    
12    if (!recoveryForm) return;
13    
14    // Обработка отправки формы
15    recoveryForm.addEventListener('submit', function(e) {
16        e.preventDefault();
17        
18        const email = emailInput.value.trim();
19        
20        if (!email) {
21            showError('Введите email');
22            return;
23        }
24        
25        if (!isValidEmail(email)) {
26            showError('Введите корректный email');
27            return;
28        }
29        
30        // Показываем загрузку без зависимости от SITE_TEMPLATE_PATH
31        submitButton.disabled = true;
32        const originalHtml = submitButton.innerHTML;
33        submitButton.dataset.originalHtml = originalHtml;
34        submitButton.innerHTML = '<span class="ui-button__text">Отправка...</span>';
35        
36        // Отправляем запрос
37        const formData = new FormData();
38        formData.append('email', email);
39        if (typeof BX !== 'undefined' && BX.bitrix_sessid) {
40            formData.append('sessid', BX.bitrix_sessid());
41        }
42        
43        fetch('/local/scripts/auth/password_recovery.php', {
44            method: 'POST',
45            body: formData
46        })
47        .then(response => response.json())
48        .then(data => {
49            if (data.success) {
50                showSuccess(data.message);
51                hideMainText();
52                showMessage();
53            } else {
54                showError(data.error || 'Произошла ошибка');
55            }
56        })
57        .catch(error => {
58            console.error('Error:', error);
59            showError('Произошла ошибка при отправке запроса');
60        })
61        .finally(() => {
62            // Восстанавливаем кнопку
63            submitButton.disabled = false;
64            submitButton.innerHTML = submitButton.dataset.originalHtml || '<span class="ui-button__text">Восстановить</span>';
65        });
66    });
67    
68    // Обработка повторной отправки
69    if (resendButton) {
70        resendButton.addEventListener('click', function() {
71            recoveryForm.dispatchEvent(new Event('submit'));
72        });
73    }
74    
75    // Функции для отображения сообщений
76    function showError(message) {
77        hideMessage();
78        const errorDiv = document.createElement('div');
79        errorDiv.className = 'modal__form-error';
80        errorDiv.textContent = message;
81        recoveryForm.insertBefore(errorDiv, recoveryForm.firstChild);
82        
83        // Убираем ошибку через 5 секунд
84        setTimeout(() => {
85            if (errorDiv.parentNode) {
86                errorDiv.parentNode.removeChild(errorDiv);
87            }
88        }, 5000);
89    }
90    
91    function showSuccess(message) {
92        hideMessage();
93        messageElement.textContent = message;
94        showMessage();
95    }
96    
97    function showMessage() {
98        messageElement.style.display = 'block';
99        if (resendButton) {
100            resendButton.style.display = 'inline-flex';
101        }
102        submitButton.style.display = 'none';
103    }
104    
105    function hideMessage() {
106        messageElement.style.display = 'none';
107        if (resendButton) {
108            resendButton.style.display = 'none';
109        }
110        submitButton.style.display = 'inline-flex';
111    }
112    
113    function hideMainText() {
114        if (mainTextElement) {
115            mainTextElement.style.display = 'none';
116        }
117    }
118    
119    function isValidEmail(email) {
120        const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
121        return emailRegex.test(email);
122    }
123});

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.