-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.html
More file actions
55 lines (51 loc) · 1.88 KB
/
auth.html
File metadata and controls
55 lines (51 loc) · 1.88 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="connection.js"></script>
<script src="api.js"></script>
<script src="valid.js"></script>
</head>
<body>
<form onsubmit="sendForm()">
<input id="username" type="text" placeholder="username">
<input id="password" type="password" placeholder="password">
<input type="submit">
</form>
<br>
<button onclick="onRegister()" id="registerButton">Registration</button>
</body>
<script>
/**
*Method for submitting the form (username, password)
*/
async function sendForm() {
event.preventDefault()
// В данном случае мы проверяем только 2 поля: имя пользователя и пароль
// Если данные при авторизации некорректны, мы возвращаем предупреждение
// Иначе успешно авторизируем пользователя и переходим на index.html
if (validateForm("auth") === false) {
alert("Authorization form incorrect")
} else {
const usernameElement = document.getElementById("username")
const username = usernameElement.value
const passwordElement = document.getElementById("password")
const password = passwordElement.value
const data = {
username: username,
password: password
};
//sending a post request to the server with form
const response = await API.auth(JSON.stringify(data))
setCookie(response)
//redirect to home page
window.location.href = "index.html"
}
}
//redirect to registration page
function onRegister() {
window.location.href = "registration.html"
}
</script>
</html>