Skip to content

Commit 9b499e7

Browse files
committed
alex changes
1 parent 96eb97c commit 9b499e7

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

BA_signin.html

+57-13
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@
8282
<div id="login-tab-content" class="tab-content">
8383
<h2 style="text-align: center;">Login</h2>
8484
<form>
85-
<input type="text" id="name" name="name" placeholder="name" required>
86-
<br>
8785
<input type="text" id="email" name="email" placeholder="email" required>
8886
<br>
8987
<input type="password" id="password" name="password" placeholder="password" required>
9088
<br>
91-
<button id="logInButton" type="submit" class="login-button">Login</button>
89+
<button id="logInButton" type="submit" class="login-button" onclick="logIn()">Login</button>
9290
</form>
9391
</div>
9492

@@ -109,6 +107,7 @@ <h2 style="text-align: center;">Sign Up</h2>
109107

110108
<script>
111109
const signup_url = 'http://localhost:8085/api/person/post?';
110+
const login_url = 'http://localhost:8085/authenticate';
112111

113112
function showTab(tabId) {
114113
// Hide all tab contents
@@ -131,7 +130,7 @@ <h2 style="text-align: center;">Sign Up</h2>
131130
"dob": encodeURIComponent(dob)
132131
};
133132

134-
console.log("fetch url: " + signup_url + new URLSearchParams(params));
133+
console.log("sign up fetch url: " + signup_url + new URLSearchParams(params));
135134

136135
fetch(signup_url + new URLSearchParams(params), {
137136
method: 'POST',
@@ -142,23 +141,68 @@ <h2 style="text-align: center;">Sign Up</h2>
142141
}
143142

144143
function logIn() {
145-
let email = document.getElementById("new-email").value;
146-
let password = document.getElementById("new-password").value;
147-
let name = document.getElementById("new-name").value;
144+
let email = document.getElementById("email").value;
145+
let password = document.getElementById("password").value;
148146

149147
const params = {
150-
email: encodeURIComponent(email),
151-
password: encodeURIComponent(password),
152-
name: encodeURIComponent(name)
148+
email: email,
149+
password: password
153150
};
154151

155-
fetch(`${url}?${new URLSearchParams(params)}`, {
156-
method: 'GET',
152+
console.log("login fetch url: " + login_url);
153+
console.log("body: " + JSON.stringify(params))
154+
fetch(login_url, {
155+
method: 'POST',
156+
headers: {
157+
'Content-Type': 'application/json',
158+
},
159+
body: JSON.stringify(params),
157160
})
158161
.then(response => response.json())
159-
.then(data => console.log(data))
162+
.then(data => {
163+
console.log(data);
164+
if (data.status==200) {
165+
window.location.replace("/stats.html");
166+
} else {
167+
console.log("bad email and password");
168+
}
169+
})
160170
.catch(error => console.error('Error:', error));
161171
}
172+
173+
function logInXML() {
174+
let email = document.getElementById("email").value;
175+
let password = document.getElementById("password").value;
176+
177+
const loginData = {
178+
email: email,
179+
password: password
180+
};
181+
182+
console.log("login fetch url: " + login_url);
183+
184+
const xhr = new XMLHttpRequest();
185+
xhr.open('POST', login_url, true);
186+
xhr.setRequestHeader('Content-Type', 'application/json');
187+
188+
xhr.onreadystatechange = function () {
189+
if (xhr.readyState === XMLHttpRequest.DONE) {
190+
if (xhr.status === 200) {
191+
const data = JSON.parse(xhr.responseText);
192+
console.log(data);
193+
if (data.status == 200) {
194+
window.location.replace("/stats.html");
195+
} else {
196+
console.log("bad email and password");
197+
}
198+
} else {
199+
console.error('Error:', xhr.statusText);
200+
}
201+
}
202+
};
203+
204+
xhr.send(JSON.stringify(loginData));
205+
}
162206
</script>
163207

164208

0 commit comments

Comments
 (0)