forked from alerez/shpptofov3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.html
79 lines (78 loc) · 2.38 KB
/
login.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ToDo/Ш++</title>
<link rel="stylesheet" href="login.css">
<link href="https://fonts.googleapis.com/css?family=Oswald&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<div class="Login">
<h1>ToDo<span style="color: darkgreen">/</span>Ш++</h1>
<div class="LoginInput">
<input v-model="nickName" type="text" placeholder="Nickname" autofocus required>
<input v-model="pass" type="password" placeholder="Password" autofocus required>
</div>
<div class="LoginButton">
<button @click="register()">Register</button>
<button @click="login()">Login</button>
</div>
</div>
</div>
<script>
const url = "https://aboyko.shpp.me/api/v2/router.php?action=";
const site = "https://shpptodov3.herokuapp.com/ToDov3/index.html";
let vue = new Vue({
el: '#app',
data: {
nickName: '',
pass: ''
},
methods: {
login(){
if(this.nickName.trim() !== '' && this.pass.trim()) {
let request = JSON.stringify({login: this.nickName, pass: this.pass});
fetch(url + 'login', {
method: 'POST',
body: request,
credentials: 'include',
headers: {
'Content-Type': 'application/json;'
},
}).then(res => res.json())
.then((response) => {
if (response.ok) {
localStorage.setItem('name', request.login);
window.location = site;
} else {
alert("Error 500. Internal server error. Please try again later")
}
});
}}},
register(){
if(this.nickName.trim() !== '' && this.pass.trim()) {
let request = JSON.stringify({login: this.nickName, pass: this.pass});
fetch(url + 'register', {
method: 'POST',
body: request,
headers: {
'Content-Type': 'application/json;'
},
}).then(res => res.json())
.then((response) => {
if (response.ok) {
this.nickName = '';
this.pass = '';
alert('ПОЗДРАВЛЯЮ ТЕПЕРЬ ВЫ ЗАРЕГИСТРИРОВАЛИСЬ \n' +
'А теперь можешь войти на сайт)')
} else {
alert("Error 500. Internal server error. Please try again later")
}
});
}},
});
</script>
</body>
</html>