-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML
More file actions
122 lines (111 loc) · 3.57 KB
/
Copy pathHTML
File metadata and controls
122 lines (111 loc) · 3.57 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
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
120
121
122
<!DOCTYPE html>
<html>
<head>
<title>FxWealth</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f5f5f5;
}
h2 {
color: #333;
}
input {
padding: 10px;
margin: 5px 0;
width: 250px;
}
button {
padding: 10px 20px;
margin-top: 10px;
cursor: pointer;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
}
#output {
margin-top: 20px;
white-space: pre-wrap;
background-color: #eee;
padding: 10px;
width: 300px;
text-align: left;
border-radius: 5px;
}
</style>
</head>
<body>
<h2>FxWealth Login</h2>
<input id="email" type="email" placeholder="Email"><br>
<input id="password" type="password" placeholder="Password"><br>
<button onclick="login()">Login</button>
<p>Don't have an account? <a href="#" onclick="showRegister()">Register</a></p>
<div id="registerForm" style="display:none;">
<h2>FxWealth Register</h2>
<input id="regName" placeholder="Full Name"><br>
<input id="regEmail" type="email" placeholder="Email"><br>
<input id="regPassword" type="password" placeholder="Password"><br>
<button onclick="register()">Register</button>
<p><a href="#" onclick="showLogin()">Back to Login</a></p>
</div>
<pre id="output"></pre>
<script>
function showRegister() {
document.getElementById('registerForm').style.display = 'block';
}
function showLogin() {
document.getElementById('registerForm').style.display = 'none';
}
async function login() {
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
try {
const res = await fetch('http://localhost:5000/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password })
});
const data = await res.json();
if(res.ok) {
document.getElementById('output').textContent = "Login successful! Redirecting...";
// Save token if your backend sends one
localStorage.setItem('token', data.token);
// Redirect to dashboard page
setTimeout(() => window.location.href = 'dashboard.html', 1000);
} else {
document.getElementById('output').textContent = data.message || JSON.stringify(data, null, 2);
}
} catch (err) {
document.getElementById('output').textContent = err.message;
}
}
async function register() {
const name = document.getElementById('regName').value;
const email = document.getElementById('regEmail').value;
const password = document.getElementById('regPassword').value;
try {
const res = await fetch('http://localhost:5000/api/auth/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, email, password })
});
const data = await res.json();
if(res.ok) {
document.getElementById('output').textContent = "Registration successful! You can now login.";
showLogin();
} else {
document.getElementById('output').textContent = data.message || JSON.stringify(data, null, 2);
}
} catch (err) {
document.getElementById('output').textContent = err.message;
}
}
</script>
</body>
</html>