forked from niyazm524/arch_client_web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.html
100 lines (99 loc) · 3.07 KB
/
auth.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Авторизация</title>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.js"></script>
</head>
<style>
.for-read,
.for-write {
width: 40%;
}
.container {
position: fixed;
top: 30%;
left: 40%;
}
label {
font-family: Verdana, Geneva, Tahoma, sans-serif;
margin-top: 8%;
margin-right: 3%;
}
#login-input,
#password_input,
#auth-button {
height: 5%;
margin-bottom: 5%;
margin-top: 5%;
}
a {
position: fixed;
top: 55%;
left: 40%;
}
</style>
<body>
<div class="container">
<form onsubmit="sendForm()" class="for-write" id="write-form">
<div class="login-div ui input">
<label for="login-input">Логин: </label>
<input id="login-input" type="text" />
</div>
<div class="password-div ui input">
<label for="password-input">Пароль: </label>
<input id="password-input" type="password" />
</div>
<div>
<button class="ui inverted green button" id="auth-button">
Авторизация
</button>
<a href="http://127.0.0.1:5500/sign_up.html">Регистрация</a>
</div>
</form>
</div>
</body>
<script>
window.onload = function isToken() {
// При загрузке страницы проверять наличие токена
if (document.cookie !== "") {
window.location.href = "index.html";
}
};
const url = "https://sys-arch.ml/api/auth/sign_in/";
async function sendForm() {
// ADD Проверка на статус ответа сервера
event.preventDefault();
// Достаем данные из формы
const usernameElement = document.getElementById("login-input");
const email = usernameElement.value;
const passwordElement = document.getElementById("password-input");
const password = passwordElement.value;
var urlencoded = new URLSearchParams(); // Создаем объект URLSearchParams()
urlencoded.append("password", password); // Добавляем в него данные, введенные пользователем
urlencoded.append("email", email);
var status;
const response = await fetch(url, {
// Отправляем данные
method: "POST",
body: urlencoded,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}).then((response) => response.json());
cookie = "token = " + response.auth_token;
document.cookie = cookie;
if (response.auth_token !== undefined ) {
window.location.href = "index.html";
}
}
</script>
</html>