auth, first setup, error handling, small fixes
This commit is contained in:
72
static/templates/signin.html
Normal file
72
static/templates/signin.html
Normal file
@ -0,0 +1,72 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Авторизация</title>
|
||||
<link rel="stylesheet" href="../styles/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<section class="form right">
|
||||
<form enctype="multipart/form-data" method="post" action="/login" id="loginForm">
|
||||
<h1 style="margin-bottom: 40px;">Добро пожаловать в Аргус</h1>
|
||||
|
||||
<label for="login">Логин или Email<span>*</span></label>
|
||||
<input placeholder="Введите логин или Email" name="email" type="text" required>
|
||||
|
||||
<label for="password">Пароль<span>*</span></label>
|
||||
<input placeholder="Введите пароль" name="password" type="password" required>
|
||||
|
||||
<button type="submit">Войти</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<video class="animation left" autoplay muted loop>
|
||||
<source src="../img/traffic.mp4" type="video/mp4">
|
||||
</video>
|
||||
<span class="copyright left"><a href="https://dribbble.com/shots/15608015-Traffic">Видеоматериал создан Igor Kozak для 10Clouds</a></span>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
// Обработка отправки формы в формате JSON
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
loginForm.addEventListener('submit', function(event) {
|
||||
|
||||
event.preventDefault();
|
||||
const formData = new FormData(loginForm);
|
||||
const jsonData = {};
|
||||
|
||||
formData.forEach((value, key) => {
|
||||
jsonData[key] = value;
|
||||
});
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/login');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
location.href = '/';
|
||||
} else if (xhr.status === 401) {
|
||||
alert('Неверный логин или пароль');
|
||||
} else {
|
||||
alert('Произошла ошибка при отправке данных');
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
// Ошибка сети
|
||||
alert('Произошла ошибка сети');
|
||||
};
|
||||
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user