forked from TeamInferno/StockInferno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.html
58 lines (54 loc) · 1.76 KB
/
signup.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
<html>
<head>
<meta charset="UTF-8">
<title>Stock Inferno - Sign Up</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
</head>
<body>
<div style="margin: 100px auto; max-width: 500px" id="main">
<div class="container">
<form action="signup" id="signup">
<h3>Sign Up</h3>
<label for="name">Name</label>
<input name="name" type="text" />
<label for="username">Username</label>
<input name="username" type="text" />
<label for="password">Password</label>
<input name="password" type="password" />
<button type="submit">Sign Up</button>
<p>Already have an account? <a href="/">Login</a></p>
</form>
</div>
</div>
<script>
// Send signup request to server
function handleSubmit(e) {
fetch('/api/signup', {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json'
}),
body: JSON.stringify({
name: e.target.name.value,
username: e.target.username.value,
password: e.target.password.value,
})
})
.then((res) => {
if (res.status !== 200) {
window.location.assign('/signup');
} else {
res.json().then((data) => {
window.localStorage.setItem('name', data.user.name);
});
window.location.assign('/home');
}
});
e.preventDefault();
}
const signupForm = document.getElementById('signup');
signupForm.addEventListener('submit', handleSubmit);
</script>
</body>
</html>