-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapproveCandidates.jsp
251 lines (228 loc) · 8.29 KB
/
approveCandidates.jsp
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.pollify.CandidateApplication" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%
if (session != null && session.getAttribute("username") != null) {
if (!"admin".equals(session.getAttribute("role"))) { // Check if the user is not admin
response.sendRedirect("accessDenied.jsp"); // Redirect if the role is not admin
return; // Stop further processing
}
} else {
response.sendRedirect("login.jsp"); // Redirect to login if session is null
return; // Stop further processing
}
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Approve Candidates</title>
<link rel="stylesheet" href="css/navbar.css">
<link rel="stylesheet" href="css/user_page.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
/* Your CSS for card design here */
:root {
--card-background: rgba(255, 255, 255, 0.7);
--primary-color: #4a90e2;
--secondary-color: #ff5f7e;
--text-color: #333;
--shadow-color: rgba(0, 0, 0, 0.2);
--border-color: rgba(255, 255, 255, 0.4);
--transition-speed: 0.3s;
--blur: 10px;
}
.container {
width: 100%;
backdrop-filter: blur(var(--blur));
text-align: center;
color: var(--text-color);
}
h2 {
font-size: 26px;
font-weight: 600;
color: #333;
margin-bottom: 20px;
opacity: 0.9;
}
.candidate-card {
background: var(--card-background);
padding: 20px;
margin: 15px 0;
border-radius: 16px;
box-shadow: 0 8px 16px var(--shadow-color);
border: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
transition: transform var(--transition-speed), box-shadow var(--transition-speed);
backdrop-filter: blur(10px);
}
.candidate-card:hover {
transform: translateY(-5px);
box-shadow: 0 12px 20px rgba(0, 0, 0, 0.2);
}
.candidate-info {
display: flex;
align-items: center;
}
.candidate-photo {
width: 70px;
height: 70px;
border-radius: 50%;
background-color: #ddd;
margin-right: 15px;
flex-shrink: 0;
background-image: linear-gradient(135deg, #6b73ff, #000dff);
}
.candidate-name {
font-size: 20px;
font-weight: 600;
color: var(--text-color);
margin: 0;
}
.candidate-description {
font-size: 14px;
color: #555;
margin-top: 5px;
opacity: 0.8;
}
.action-buttons {
display: flex;
gap: 10px;
}
.action-buttons button {
padding: 10px 20px;
font-size: 14px;
font-weight: 500;
border-radius: 8px;
border: none;
cursor: pointer;
transition: background-color var(--transition-speed), transform var(--transition-speed);
color: #fff;
}
.approve-btn {
background: linear-gradient(135deg, var(--primary-color), #007aff);
box-shadow: 0 4px 8px rgba(74, 144, 226, 0.4);
}
.reject-btn {
background: linear-gradient(135deg, var(--secondary-color), #ff4081);
box-shadow: 0 4px 8px rgba(255, 95, 126, 0.4);
}
.approve-btn:hover, .reject-btn:hover {
transform: translateY(-3px);
opacity: 0.9;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
</style>
</head>
<body>
<%
String username = (session != null) ? (String) session.getAttribute("username") : null; // Get the username if session exists
String successMessage = (String) session.getAttribute("successMessage");
String errorMessage = (String) session.getAttribute("errorMessage");
// Clear the messages after displaying
if (successMessage != null) {
session.removeAttribute("successMessage");
}
if (errorMessage != null) {
session.removeAttribute("errorMessage");
}
%>
<nav>
<div class="logo">Pollify</div>
<div class="menu">
<% if(username == null) { %>
<a href="home.jsp">Home</a>
<a href="register.jsp">Register</a>
<a href="login.jsp">Login</a>
<% } %>
<% if (username != null) { %>
<a>Welcome, <%= username %>!</a>
<a href="logout.jsp">Logout</a> <!-- Link to logout servlet -->
<% } %>
</div>
</nav>
<div class="container">
<div class="sidebar">
<h2>Admin</h2>
<ul>
<li><a href="adminDashboard.jsp" >
<i class="fas fa-calendar"></i> Set Voting Period
</a></li>
<li><a href="pendingResult">
<i class="fas fa-trophy"></i> Declare Result
</a></li>
<li><a href="#" class="active"">
<i class="fas fa-thumbs-up"></i> Approve Candidate
</a></li>
<li><a href="viewVotingPeriods">
<i class="fas fa-history"></i> View Voting Periods
</a></li>
<li><a href="sendNotification.jsp">
<i class="fas fa-bell"></i> Send Notification
</a></li>
</ul>
</div>
<div class="content">
<div id="content-area">
<!-- Display success or error messages -->
<div>
<%
// Display success message
if (successMessage != null) {
out.println("<div style='color: green; font-weight: bold;'>" + successMessage + "</div>");
}
// Display error message
if (errorMessage != null) {
out.println("<div style='color: red; font-weight: bold;'>Error: " + errorMessage + "</div>");
}
%>
</div>
</div>
<h2>Approve Candidates</h2>
<%
// Retrieve the list of candidate applications from the request
List<CandidateApplication> applications = (List<CandidateApplication>) request.getAttribute("candidateApplications");
if (applications != null && !applications.isEmpty()) {
for (CandidateApplication app : applications) { // Changed 'application' to 'app'
%>
<div class="candidate-card">
<div class="candidate-info">
<div>
<p class="candidate-name"><%= app.getUsername() %></p> <!-- Use getUsername() method -->
<p class="candidate-description"><%= app.getEmail() %></p> <!-- Use getEmail() method -->
<p class="candidate-description"><%= app.getApplicationDate() %></p> <!-- Use getApplicationDate() method -->
</div>
</div>
<div class="action-buttons">
<button class="approve-btn" onclick="approveCandidate('<%= app.getUsername() %>', '<%= app.getEmail() %>')">Approve</button>
<button class="reject-btn" onclick="rejectCandidate('<%= app.getUsername() %>', '<%= app.getEmail() %>')">Reject</button>
</div>
</div>
<%
}
} else {
%>
<div>
<p>No Pending Requests Found.</p>
</div>
<%
}
%>
</div>
</div>
<script>
function approveCandidate(username, email) {
// Redirect to the approve servlet with the username and email as query parameters
window.location.href = 'approved?username=' + encodeURIComponent(username) + '&email=' + encodeURIComponent(email);
}
function rejectCandidate(username, email) {
// Redirect to the reject servlet with the username and email as query parameters
window.location.href = 'rejected?username=' + encodeURIComponent(username) + '&email=' + encodeURIComponent(email);
}
</script>
</body>
</html>