beta 2.0
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
function deleteAuthToken() {
|
||||
document.cookie = "auth_token=; expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
||||
window.location.href = "/login";
|
||||
}
|
||||
|
||||
// Вспомогательные функции для уведомлений
|
||||
function showAlert(type, message) {
|
||||
const alertContainer = document.getElementById('alertContainer');
|
||||
|
||||
// Очищаем старые алерты
|
||||
alertContainer.innerHTML = '';
|
||||
|
||||
// Создаем новый алерт
|
||||
const alert = document.createElement('div');
|
||||
alert.className = `alert alert-${type} alert-dismissible fade show shadow`;
|
||||
|
||||
// Иконка для типа алерта
|
||||
const icon = getAlertIcon(type);
|
||||
|
||||
alert.innerHTML = `
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="bi ${icon} me-2 fs-5"></i>
|
||||
<div class="flex-grow-1">${message}</div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
alertContainer.appendChild(alert);
|
||||
|
||||
// Автоматическое удаление через 5 секунд
|
||||
setTimeout(() => {
|
||||
if (alert.parentNode) {
|
||||
alert.classList.remove('show');
|
||||
setTimeout(() => alert.remove(), 150);
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function getAlertIcon(type) {
|
||||
const icons = {
|
||||
'success': 'bi-check-circle-fill',
|
||||
'warning': 'bi-exclamation-triangle-fill',
|
||||
'danger': 'bi-x-circle-fill',
|
||||
'info': 'bi-info-circle-fill'
|
||||
};
|
||||
return icons[type] || 'bi-info-circle-fill';
|
||||
}
|
||||
|
||||
document.getElementById("changePasswordForm").addEventListener("submit", async function (e) {
|
||||
e.preventDefault(); // ❌ перезагрузка страницы
|
||||
|
||||
const passwordInput = document.getElementById("newPassword");
|
||||
const newPassword = passwordInput.value.trim();
|
||||
|
||||
if (!newPassword) {
|
||||
showAlert("warning", "Введите новый пароль");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("/login", {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ password: newPassword })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status === "ok") {
|
||||
showAlert("success", "Пароль успешно изменён");
|
||||
|
||||
// очистить поле
|
||||
passwordInput.value = "";
|
||||
|
||||
// закрыть dropdown
|
||||
const btn = document.getElementById("changePasswordBtn");
|
||||
const dropdown = bootstrap.Dropdown.getOrCreateInstance(btn);
|
||||
dropdown.hide();
|
||||
} else {
|
||||
showAlert("danger", data.errorMessage || "Ошибка изменения пароля");
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert("danger", "Ошибка соединения с сервером");
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user