Skip to content

Commit 55c147a

Browse files
committed
everything working
1 parent 64349d2 commit 55c147a

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

BD_profile.html

+29-11
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,31 @@
1616
email = (JSON.parse(decode(getCookie("token")))).sub;
1717
id = ((JSON.parse(decode(getCookie("token")))).id).toString();
1818
console.log(id);
19+
20+
date = new Date();
21+
day = date.getDate();
22+
month = date.getMonth() + 1;
23+
year = (date.getFullYear()) -2000;
24+
currentDate = `0${month}-${day}-${year}`;
25+
console.log(currentDate)
1926

2027
function update() {
2128
//pull from backend and update values
2229
// placeholders
23-
function getRandomInt(max) {
24-
return Math.floor(Math.random() * max);
25-
}
26-
steps = (getRandomInt(100));
27-
calories = (getRandomInt(1000));
30+
var requestOptions = {
31+
method: 'GET',
32+
redirect: 'follow'
33+
};
34+
35+
fetch("http://localhost:8085/api/person/" + id, requestOptions)
36+
.then(response => response.text())
37+
.then(result => {
38+
const stats = JSON.parse(result).stats[currentDate];
39+
document.getElementById("welcome").innerHTML = "Welcome " + email + "!";
40+
document.getElementById("steps").innerHTML = stats ? stats.steps : "N/A";
41+
document.getElementById("calories").innerHTML = stats ? stats.calories : "N/A";
42+
})
43+
.catch(error => console.log('error', error));
2844
//placeholders
2945
document.getElementById("welcome").innerHTML = "Welcome " + email + "!";
3046
document.getElementById("steps").innerHTML = steps;
@@ -38,11 +54,6 @@
3854
document.getElementById("calories").innerHTML = calories;
3955
}
4056
function post() {
41-
date = new Date();
42-
day = date.getDate();
43-
month = date.getMonth() + 1;
44-
year = (date.getFullYear()) -2000;
45-
currentDate = `0${month}-${day}-${year}`;
4657
console.log(currentDate);
4758
steps = document.getElementById("steps").innerHTML;
4859
calories = document.getElementById("calories").innerHTML;
@@ -88,13 +99,18 @@
8899
if (data.status!=401 || data.status!=400) {
89100
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
90101
alert("user deleted!")
91-
//window.location.replace("/Lesson_Frontend/sign_in/");
102+
window.location.replace("/Lesson_Frontend/sign_in/");
92103
} else {
93104
console.log("bad email and password");
94105
}
95106
})
96107
.catch(error => console.log('error', error));
97108
}
109+
function signOut() {
110+
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
111+
alert("signed out!")
112+
window.location.replace("/Lesson_Frontend/sign_in/");
113+
}
98114
</script>
99115

100116
<body onload="update()">
@@ -111,6 +127,8 @@
111127
<button onClick="edit()">Edit</button>
112128
<button onClick="post()">Update</button>
113129
<div></div>
130+
<button onClick="signOut()">Sign Out</button>
131+
<div></div>
114132
<button onClick="delUser()">Delete user</button>
115133
</div>
116134
</div>

0 commit comments

Comments
 (0)