fix jss 0.149
This commit is contained in:
@@ -4,7 +4,7 @@ function getToken() {
|
||||
function tokenCheck(){
|
||||
const token = getToken();
|
||||
if (token) {
|
||||
window.location.href = "https://ru.homyk.space/main";
|
||||
window.location.href = "https://ru.homyk.space/main/";
|
||||
}
|
||||
}
|
||||
document.getElementById('loginForm').addEventListener('submit', async function (e) {
|
||||
@@ -29,7 +29,7 @@ document.getElementById('loginForm').addEventListener('submit', async function (
|
||||
// в sessionstorage до перезахода в браузер(
|
||||
sessionStorage.setItem("token", data.access_token);
|
||||
|
||||
window.location.href = 'https://ru.homyk.space/main';
|
||||
window.location.href = 'https://ru.homyk.space/main/';
|
||||
} else { //парсинг и вывод ошибок, если есть
|
||||
if (Array.isArray(data.detail)) {
|
||||
const messages = data.detail.map(e => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
function getToken() {
|
||||
return localStorage.getItem("token") || sessionStorage.getItem("token");
|
||||
}
|
||||
|
||||
function tokenCheck() {
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
@@ -8,62 +9,57 @@ function tokenCheck(){
|
||||
}
|
||||
}
|
||||
|
||||
tokenCheck()
|
||||
document.getElementById('logoutForm').addEventListener('submit', async function (e) {
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
tokenCheck();
|
||||
|
||||
document.getElementById('logoutForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem("token");
|
||||
sessionStorage.removeItem("token");
|
||||
tokenCheck();
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const form = document.querySelector(".form-info");
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
document.querySelector(".form-info").addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
// try {
|
||||
// собираем данные из формы
|
||||
const name = document.getElementById('ffname').value || "";
|
||||
const middlename = document.getElementById('fmname').value || "";
|
||||
const surname = document.getElementById('flname').value || "";
|
||||
const text_field = document.getElementById('text_field')?.value || "";
|
||||
const food = document.querySelector('input[name="food"]:checked')?.value || "";
|
||||
const types_of_alco = Array.from(document.querySelectorAll('input[name="drink"]:checked'))
|
||||
.map(el => el.value)
|
||||
.join(', ');
|
||||
|
||||
const token = getToken();
|
||||
|
||||
const guestData = {
|
||||
name: name,
|
||||
middlename: middlename,
|
||||
surname: surname,
|
||||
text_field: text_field,
|
||||
name: document.getElementById('ffname').value || "",
|
||||
middlename: document.getElementById('fmname').value || "",
|
||||
surname: document.getElementById('flname').value || "",
|
||||
text_field: document.getElementById('text_field')?.value || "",
|
||||
activated: true,
|
||||
types_of_food: food,
|
||||
types_of_alco: types_of_alco
|
||||
types_of_food: document.querySelector('input[name="food"]:checked')?.value || "",
|
||||
types_of_alco: Array.from(document.querySelectorAll('input[name="drink"]:checked'))
|
||||
.map(el => el.value)
|
||||
.join(', ')
|
||||
};
|
||||
console.log(guestData)
|
||||
|
||||
// отправка на /api/update с Authorization
|
||||
// const updateResponse = await fetch('/api/update', {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// 'Authorization': `Bearer ${token}`
|
||||
// },
|
||||
// body: JSON.stringify(guestData)
|
||||
// });
|
||||
console.log(guestData);
|
||||
|
||||
// if (!updateResponse.ok) {
|
||||
// throw new Error('Ошибка при отправке формы');
|
||||
// }
|
||||
|
||||
// const updateData = await updateResponse.json();
|
||||
// console.log('Форма успешно отправлена:', updateData);
|
||||
|
||||
// } catch (err) {
|
||||
// console.error(err);
|
||||
// alert('Ошибка: ' + err.message);
|
||||
// }
|
||||
});
|
||||
try {
|
||||
const response = await fetch('/api/update', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(guestData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const err = await response.json();
|
||||
throw new Error(JSON.stringify(err.detail || 'Ошибка при отправке'));
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Успешно:', data);
|
||||
alert('Данные сохранены!');
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert('Ошибка: ' + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user