-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (103 loc) · 3.57 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Login - PawPal</TITLE>
<link rel="stylesheet" href="https://unpkg.com/98.css">
<STYLE>
.login-container {
width: 300px;
padding: 20px;
margin: 0 auto;
}
input[type="text"],
input[type="password"] {
margin-bottom: 10px;
padding: 5px;
width: 100%;
border: 1px solid #000000;
}
#invalid {
color: red;
font-size: 12px;
margin-bottom: 10px;
}
</STYLE>
</HEAD>
<BODY BGCOLOR=#c0c0c0 TEXT=#000000>
<DIV id="login-container" class="login-container">
<DIV class="window" style="width: 300px">
<DIV class="title-bar">
<DIV class="title-bar-text">Login - PawPal!</DIV>
<DIV class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close"></button>
</DIV>
</DIV>
<DIV class="window-body">
<center>
<h4 style="font-size: 16px">Login</h4>
</center>
<form id="login-form" action="home.html" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required="required" />
<label for="password">Password:</label>
<input type="password" id="password" name="password" required="required" />
<DIV id="invalid"></DIV>
<input type="checkbox" id="remember-me" />
<label for="remember-me">Remember me</label>
<br>
<br>
<center>
<input type="submit" value="Sign In" />
<!--- <input type="submit" value="Sign Up" /> ---->
<br>
<p>Version: b58862f</p>
</center>
</form>
</DIV>
</DIV>
</DIV>
<SCRIPT TYPE="text/javascript">
</SCRIPT>
<SCRIPT TYPE="text/javascript">
document.getElementById('login-form').onsubmit = function (event) {
event.preventDefault();
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var rememberMe = document.getElementById('remember-me').checked;
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.meower.org/auth/login', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (!data.error) {
var ws = new WebSocket('wss://server.meower.org/?v=1&token=' + data.token);
ws.onmessage = function (event) {
var data = JSON.parse(event.data);
if (data.cmd === 'auth') {
if (rememberMe) {
localStorage.setItem('userData', JSON.stringify(data.val));
} else {
sessionStorage.setItem('userData', JSON.stringify(data.val));
}
ws.onclose();
}
};
document.getElementById('invalid').innerHTML = '';
window.location.href = 'home.html';
} else {
document.getElementById('invalid').innerHTML = 'Invalid credentials. Please try again.';
}
} else {
document.getElementById('invalid').innerHTML = 'Error connecting to server.';
}
}
};
xhr.send(JSON.stringify({ username: username, password: password }));
};
</SCRIPT>
</BODY>
</HTML>