// ИНИЦИАЛИЗИРУЕМ VUEAPP var app = new Vue({ el: '#auth_form', data() { return { formData: { login: '', password: '', savepassword: false } }; }, methods: { handleSubmit() { window.Auth(this.formData); } } }); // ФУНКЦИЯ ОТПРАВКИ ФОРМЫ АВТОРИЗАЦИИ window.Auth = function(account) { // Проверка состояния интернет-соединения перед отправкой запроса if (!navigator.onLine) { // Показать алерт об отсутствии соединения show_hide_alert(false, 'Ошибка авторизации', 'Пожалуйста, проверьте ваше интернет-соединение и попробуйте снова.', 1); return; // Прекратить выполнение функции } document.getElementById('AuthSidePanel').style.pointerEvents = 'none'; document.getElementById('authbutton').disabled = true; fetch('https://back.metamsk.ru/client/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(account) }) .then(response => { if (response.status === 200) { return response.json(); // Вернуть JSON тело ответа } else { show_hide_alert(false, 'Ошибка авторизации', 'Похоже что вы ввели неверный логин или пароль, попробуйте снова.', 1); document.getElementById('AuthSidePanel').style.pointerEvents = 'all'; document.getElementById('authbutton').disabled = false; throw new Error('Ошибка авторизации'); } }) .then(data => { if (account.savepassword) { LauncherAPI.saveAccount(account.login, account.password); } LauncherAPI.SetAuthToken(data.token) LauncherAPI.onGetLauncherData((event, LauncherInfo) => { if (LauncherInfo[0]) { open_panel('LaunchSidePanel', 'AuthSidePanel', () => open_panel('AuthSidePanel', 'LaunchSidePanel', null, true, ['gamestartbtn'], () => LauncherAPI.ExitAccount()), true); LauncherAPI.FastCheckFiles() } else { open_panel('DownloadSidePanel', 'AuthSidePanel', () => open_panel('AuthSidePanel', 'DownloadSidePanel', null, true, ['toinstallpathpanelbtn']), true); } }) LauncherAPI.GetLauncherData() document.getElementById('AuthSidePanel').style.pointerEvents = 'all'; document.getElementById('authbutton').disabled = false; }) .catch(error => { // Обработка ошибок сети или доступности API console.error('Error:', error); if (error.message === 'Ошибка авторизации') { // Специфическая обработка ошибок авторизации show_hide_alert(false, 'Ошибка авторизации', error.message, 1); document.getElementById('AuthSidePanel').style.pointerEvents = 'all'; document.getElementById('authbutton').disabled = false; } else { // Обработка других типов ошибок, в том числе когда API недоступно show_hide_alert(false, 'Сервис недоступен', 'Не удалось связаться с сервером. Пожалуйста, попробуйте позже.', 1); document.getElementById('AuthSidePanel').style.pointerEvents = 'all'; document.getElementById('authbutton').disabled = false; } }); };