-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount.html
101 lines (99 loc) · 3.32 KB
/
account.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
<!DOCTYPE html>
<html>
<head>
<script async src="https://arc.io/widget.min.js#N3KzQsou">
</script>
<meta charset='UTF-8'>
<meta name='description' content='Login or Sign Up here'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta name='robots' content='index, follow'>
<link rel='shortcut icon' href='/starlite-logo.png' type='image/png'>
<link rel='stylesheet' type='text/css' href='/style/account.css' />
<title>Starlite | Login / Signup</title>
</head>
<body>
< <u>Back</u>
</a>
<div class="form">
<img src='/starlite-logo.png'/>
<h1 class='content-title'>Sign up/Login</h1>
<div class="input">
<b>Username:</b>
<input type="text" id="usernameForm"/>
</div>
<div class="input">
<b>Password:</b>
<input type="password" id="passwordForm"/>
</div>
<button id="submit" class='submit'>Log in</button>
<button class="newaccount" id='newaccount'>Create Account</button>
<script>
var socket = new WebSocket('wss://'+window.location.hostname+'/server');
function auth(username, password, callback) {
socket.send(JSON.stringify({
task: 'auth',
operation: 'database',
username: username,
password: password,
}));
socket.onmessage = function(data) {
callback(JSON.parse(data.data));
}
}
function create(username, password, callback) {
socket.send(JSON.stringify({
task: 'new',
operation: 'database',
username: username,
password: password,
}))
}
socket.onclose = function() {
console.log('Disconnected');
reconnect();
}
function reconnect() {
socket = new WebSocket('wss://'+window.location.hostname+'/server');
socket.onopen = function() {
console.log('Reconnected')
}
socket.onclose = function() {
console.log('Disconnected');
reconnect();
}
}
var submit=document.getElementById("submit");
var newaccount=document.getElementById("newaccount");
submit.addEventListener("click", function() {
var usernameInput=document.getElementById("usernameForm");
var passwordInput=document.getElementById("passwordForm");
auth(usernameInput.value, passwordInput.value, function(auth) {
if (auth.authencated) {
sessionStorage.username = usernameInput.value;
sessionStorage.token = auth.token;
window.location.href = '/dashboard';
} else {
alert('Incorrect Password');
}
});
});
newaccount.addEventListener("click", function(){
var usernameInput=document.getElementById("usernameForm");
var passwordInput=document.getElementById("passwordForm");
auth(usernameInput.value, passwordInput.value, function(data) {
console.log(data);
if (data.isAccount) {
alert("Account Taken");
} else {
socket.onmessage = function(){};
create(usernameInput.value, passwordInput.value);
sessionStorage.username = usernameInput.value;
sessionStorage.token = data.token;
window.location.href = "/dashboard";
}
});
});
</script>
</div>
</body>
</html>