-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.html
211 lines (196 loc) · 7.55 KB
/
profile.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile Card</title>
<link rel="stylesheet" href="css/profile.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/side.css">
<!-- Font Awesome CDN Link for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
</head>
<body>
<div class="hamburger-menu">
<i class="fas fa-bars"></i>
</div>
<!-- Sidebar for large screens -->
<div class="sidebar">
<div class="logo">
<ul class="menu">
<li>
<a href="dashboard.html">
<i class="fas fa-tachometer-alt"></i>
<span>Dashboard</span>
</a>
</li>
<li class="active">
<a href="profile.html">
<i class="fas fa-user"></i>
<span>Profile</span>
</a>
</li>
<li>
<a href="addTask.html">
<i class="fas fa-plus"></i>
<span>Add Task</span>
</a>
</li>
<li>
<a href="all-tasks.html">
<i class="fas fa-tasks"></i>
<span>All Tasks</span>
</a>
</li>
<li>
<a href="completed-tasks.html">
<i class="fas fa-check"></i>
<span>Completed Tasks</span>
</a>
</li>
<li>
<a href="pending.html">
<i class="fas fa-clock"></i>
<span>Pending Tasks</span>
</a>
</li>
<li>
<a href="in-progress.html">
<i class="fas fa-spinner"></i>
<span>In-progress</span>
</a>
</li>
<li class="logout">
<a href="javascript:void(0);" id="logout-button">
<i class="fas fa-sign-out-alt"></i>
<span>Logout</span>
</a>
</li>
</ul>
</div>
</div>
<!-- Navbar for small screens -->
<div class="navbar">
<div class="navbar-header">
<span>Menu</span>
<i class="fas fa-times close-icon"></i>
</div>
<ul class="nav-menu">
<li><a href="#">Dashboard</a></li>
<li><a href="profile.html">Profile</a></li>
<li><a href="addTask.html">Add Tasks</a></li>
<li><a href="all-tasks.html">All Tasks</a></li>
<li><a href="completed-tasks.html">Completed Tasks</a></li>
<li><a href="pending.html">Pending Tasks</a></li>
<li><a href="in-progress.html">In-Progress Tasks</a></li>
<li><a href="#">Logout</a></li>
</ul>
</div>
<!-- HEADER SECTION -->
<div class="main--content">
<div class="header--wrapper">
<div class="header--title">
<h2>TaskFlow</h2>
<span>Dashboard</span>
</div>
<div class="user--info">
<!-- <div class="search--box">
<i class="fa-solid fa-search"></i>
<input type="text" placeholder="Search"/>
</div> -->
<!-- <div class="welcome-message">
Welcome!
</div> -->
</div>
</div>
<!-- PROFILE TABLE -->
<div class="form-main-container">
<div class="profile-card">
<div class="profile-header">
<h2>Profile</h2>
</div>
<div class="profile-body">
<div class="profile-info">
<i class="fas fa-user"></i>
<span id="profile-name"></span>
</div>
<div class="profile-info">
<i class="fas fa-envelope"></i>
<span id="profile-email"></span>
</div>
<div class="profile-info">
<i class="fas fa-phone"></i>
<span id="profile-phone"></span>
</div>
<div class="profile-footer">
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Check if token exists in localStorage
if (!localStorage.getItem('Token')) {
// Redirect to login page if token is missing
window.location.href = '/auth/login.html';
return;
}
fetchUserProfile();
document.getElementById('logout-button').addEventListener('click', logout);
});
async function fetchUserProfile() {
try {
const response = await fetch('http://localhost:8080/api/user/profile', {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token')
}
});
if (!response.ok) {
throw new Error('Failed to fetch user profile');
}
const userProfile = await response.json();
console.log("user profile", userProfile);
updateWelcomeMessage(userProfile.userProfileResponseInfo.firstName);
updateProfileInfo(userProfile.userProfileResponseInfo);
} catch (error) {
console.error('Error fetching user profile:', error);
// Handle error if needed
}
}
function updateWelcomeMessage(firstName) {
const welcomeMessage = document.querySelector('.welcome-message');
if (welcomeMessage) {
welcomeMessage.textContent = `Welcome ${firstName}!`;
}
}
function updateProfileInfo(profile) {
document.getElementById('profile-name').textContent = profile.firstName;
document.getElementById('profile-email').textContent = profile.email;
document.getElementById('profile-phone').textContent = profile.phoneNumber;
}
async function logout() {
try {
const response = await fetch('http://localhost:8080/api/auth/logout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token')
}
});
if (!response.ok) {
throw new Error('Failed to logout');
}
// Clear local storage and redirect to login page
localStorage.removeItem('Token');
alert('Logged out successfully!');
window.location.href = '/auth/login.html';
} catch (error) {
console.error('Error logging out:', error);
alert('Error logging out. Please try again.');
}
}
</script>
</body>
</html>