-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanother
More file actions
71 lines (66 loc) · 2.54 KB
/
another
File metadata and controls
71 lines (66 loc) · 2.54 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>Sign Up / Log In Example</title>
<style>
body { font-family: Arial, sans-serif; }
.form-container { margin-top: 20px; }
.hidden { display: none; }
button { margin: 5px; padding: 8px 16px; }
input { margin: 4px 0; padding: 6px; width: 200px; }
</style>
</head>
<body>
<h2>Welcome!</h2>
<button onclick="showSignUp()">Sign Up</button>
<button onclick="showLogIn()">Log In</button>
<div id="signup-form" class="form-container hidden">
<h3>Sign Up</h3>
<input id="signup-username" placeholder="Username" required /><br>
<input id="signup-password" type="password" placeholder="Password" required /><br>
<button onclick="submitSignUp()">Submit</button>
<div id="signup-message"></div>
</div>
<div id="login-form" class="form-container hidden">
<h3>Log In</h3>
<input id="login-username" placeholder="Username" required /><br>
<input id="login-password" type="password" placeholder="Password" required /><br>
<button onclick="submitLogIn()">Submit</button>
<div id="login-message"></div>
</div>
<script>
function showSignUp() {
document.getElementById('signup-form').classList.remove('hidden');
document.getElementById('login-form').classList.add('hidden');
document.getElementById('signup-message').textContent = '';
}
function showLogIn() {
document.getElementById('login-form').classList.remove('hidden');
document.getElementById('signup-form').classList.add('hidden');
document.getElementById('login-message').textContent = '';
}
async function submitSignUp() {
const username = document.getElementById('signup-username').value;
const password = document.getElementById('signup-password').value;
const res = await fetch('/signup', {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password })
});
const data = await res.json();
document.getElementById('signup-message').textContent = data.message;
}
async function submitLogIn() {
const username = document.getElementById('login-username').value;
const password = document.getElementById('login-password').value;
const res = await fetch('/login', {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password })
});
const data = await res.json();
document.getElementById('login-message').textContent = data.message;
}
</script>
</body>
</html>