-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
404 lines (316 loc) · 14.2 KB
/
index.php
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php
session_start();
require_once "./configs/dbconnection.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Secure Vote | Home</title>
<!-- Favicon -->
<link rel="icon" href="../assets/img/brand/favicon.png" type="image/png">
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700">
<!-- Icons -->
<link rel="stylesheet" href="../assets/vendor/nucleo/css/nucleo.css" type="text/css">
<link rel="stylesheet" href="../assets/vendor/@fortawesome/fontawesome-free/css/all.min.css" type="text/css">
<!-- Argon CSS -->
<link rel="stylesheet" href="../assets/css/argon.css?v=1.2.0" type="text/css">
<!-- Sweet Alert -->
<script src="../assets/js/core/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.11.0/sweetalert2.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.11.0/sweetalert2.all.min.js"></script>
</head>
<body class="bg-default">
<!-- Navbar -->
<nav id="navbar-main" class="navbar navbar-horizontal navbar-transparent navbar-main navbar-expand-lg navbar-light">
<div class="container">
<a class="navbar-brand" href="results-dash.php">
<img src="../assets/img/brand/white.png">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse navbar-custom-collapse collapse" id="navbar-collapse">
<div class="navbar-collapse-header">
<div class="row">
<div class="col-6 collapse-brand">
<a href="results-dash.php">
<img src="../assets/img/brand/blue.png">
</a>
</div>
<div class="col-6 collapse-close">
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
<span></span>
<span></span>
</button>
</div>
</div>
</div>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a href="index.php" class="nav-link">
<span class="nav-link-inner--text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="results-dash.php" class="nav-link">
<span class="nav-link-inner--text">Results Dashboard</span>
</a>
</li>
<li class="nav-item">
<a href="aboutus.php" class="nav-link">
<span class="nav-link-inner--text">About Us</span>
</a>
</li>
</ul>
<hr class="d-lg-none" />
<ul class="navbar-nav align-items-lg-center ml-lg-auto">
<li class="nav-item">
<a class="nav-link nav-link-icon" href="https://facebook.com/chris.kay.754703" target="_blank" data-toggle="tooltip" data-original-title="Be my friend on Facebook">
<i class="fab fa-facebook-square"></i>
<span class="nav-link-inner--text d-lg-none">Facebook</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link nav-link-icon" href="https://www.instagram.com/christinenyathira" target="_blank" data-toggle="tooltip" data-original-title="Follow me on Instagram">
<i class="fab fa-instagram"></i>
<span class="nav-link-inner--text d-lg-none">Instagram</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link nav-link-icon" href="https://twitter.com/nyathiraa" target="_blank" data-toggle="tooltip" data-original-title="Follow me on Twitter">
<i class="fab fa-twitter-square"></i>
<span class="nav-link-inner--text d-lg-none">Twitter</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link nav-link-icon" href="https://github.com/nyathirak" target="_blank" data-toggle="tooltip" data-original-title="Star me on Github">
<i class="fab fa-github"></i>
<span class="nav-link-inner--text d-lg-none">Github</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Header -->
<!-- Header -->
<!-- Main content -->
<div class="main-content" >
<!-- Header -->
<div class="header bg-gradient-primary py-5 py-lg-5 pt-lg-7">
<div class="container">
<div class="header-body text-center mb-7">
<div class="row justify-content-center">
<div class="col-xl-5 col-lg-6 col-md-8 px-5">
<h1 class="text-white">Welcome!</h1>
<p class="text-lead text-white"> Log in to be a part of the election.</p>
</div>
</div>
</div>
</div>
<div class="separator separator-bottom separator-skew zindex-100">
<svg x="0" y="0" viewBox="0 0 2560 100" preserveAspectRatio="none" version="1.1" xmlns="http://www.w3.org/2000/svg">
<polygon class="fill-default" points="2560 0 2560 100 0 100"></polygon>
</svg>
</div>
</div>
<!-- Page content -->
<div class="container mt--8 pb-5">
<div class="row justify-content-center">
<div class="col-lg-5 col-md-7">
<div class="card bg-secondary border-0 mb-0">
<div class="card-body px-lg-5 py-lg-5">
<form method="POST" autocomplete="off" autofocus action="">
<div class="text-center text-muted mb-4">
<h3>Sign in with Voting Credentials</h3>
</div>
<div class="form-group mb-3">
<div class="input-group input-group-merge input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-phone" aria-hidden="true"></i></span>
</div>
<input class="form-control form-control-md" name="phonenumber" id="phonenumber" placeholder="Phone Number" type="text" required>
</div>
</div>
<div class="form-group">
<div class="input-group input-group-merge input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-id-card"></i></span>
</div>
<input class="form-control form-control-md" name="userid" id="userid" placeholder="Voter/Admin ID" type="text" required>
</div>
</div>
<div class="form-group">
<div class="input-group input-group-merge input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-envelope"></i></span>
</div>
<input class="form-control form-control-md" name="email" id="email" placeholder="Email" type="email" required>
</div>
</div>
<div class="text-center">
<button name="sign_in" type="submit" class="btn btn-primary my-4">Sign in</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<!-- Footer -->
<footer class="footer-main pt-0">
<div class="container">
<div class="row align-items-center justify-content-lg-between">
<div class="col-lg-6">
<div class="copyright text-center text-lg-left text-muted">
© 2021 <a href="" class="font-weight-bold ml-1" target="_blank">Nyathira Kanga</a>
</div>
</div>
<div class="col-lg-6">
<ul class="nav nav-footer justify-content-center justify-content-lg-end">
<li class="nav-item">
<a href="https://github.com/creativetimofficial/argon-dashboard/blob/master/LICENSE.md" class="nav-link" target="_blank">MIT License</a>
</li>
</ul>
</div>
</div>
</footer>
</div>
</div>
<!-- Argon Scripts -->
<!-- Core -->
<script src="../assets/vendor/jquery/dist/jquery.min.js"></script>
<script src="../assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="../assets/vendor/js-cookie/js.cookie.js"></script>
<script src="../assets/vendor/jquery.scrollbar/jquery.scrollbar.min.js"></script>
<script src="../assets/vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js"></script>
<!-- Argon JS -->
<script src="../assets/js/argon.js?v=1.2.0"></script>
</body>
</html>
<?php
require_once './vendor/autoload.php';
$token = bin2hex(random_bytes(50)); // generate unique token
$token = substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyz"), 0, 6);
//$tokenhash = password_hash($token, PASSWORD_BCRYPT);
//echo $tokenhash;
$smtp_host_ip = gethostbyname('smtp.gmail.com');
// But for others only the smtp address
$smtp_host_ip = 'smtp.gmail.com';
// Create the Transport
$transport = (new Swift_SmtpTransport($smtp_host_ip, 465, 'ssl'))
->setUsername('securevote202@gmail.com')
->setPassword('nyathirakanga@22');
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
function sendVerificationEmail($email_entered,$token)
{
global $mailer;
$body = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>One Time Password</title>
</head>
<body>
<div class="wrapper">
<p> Hi '.$email_entered.',</p>
<p><b> ------------- CONFIDENTIAL: DO NOT SHARE WITH ANYONE -------------------</b></p>
<p> Take note of this One Time Password and use it to login to Secure Voting System and be a part of the election here.</p>
<p><b> '.$token.'</b> </p>
</div>
</body>
</html>';
// Create a message
$message = (new Swift_Message('Your One Time Password'))
->setFrom('securevote202@gmail.com')
->setTo($email_entered)
->setBody($body, 'text/html');
// Send the message
$result = $mailer->send($message);
if ($result > 0) {
return true;
} else {
return false;
}
}
if (isset($_POST["sign_in"]))
{
$userid_entered = mysqli_real_escape_string($conn, $_POST["userid"]);
$phonenumber_entered = mysqli_real_escape_string($conn, $_POST["phonenumber"]);
$email_entered = mysqli_real_escape_string($conn, $_POST["email"]);
$sqlquery="SELECT * FROM users WHERE UserID = '$userid_entered' LIMIT 1";
$query_result = $conn->query($sqlquery);
if ($query_result->num_rows > 0)
{
$_SESSION["control"] = $query_result->fetch_assoc();
$phonenumber_stored = $_SESSION["control"]["PhoneNumber"];
$userid_stored = $_SESSION["control"]["UserID"];
$username_stored = $_SESSION["control"]["OtherNames"];
$email_stored = $_SESSION["control"]["Email"];
$status = $_SESSION["control"]["Status"];
$updatequery="UPDATE users SET Token ='$token' WHERE UserID = '$userid_entered' LIMIT 1";
$query_result = $conn->query($updatequery);
if ($phonenumber_entered == $phonenumber_stored && $userid_entered == $userid_stored && $email_entered == $email_stored )
{
if ($status==NULL ){
sendVerificationEmail($email_entered,$token);
echo '
<script type="text/javascript">
$(document).ready(function(){
swal({
title: "Hi!" ,
text: "We just sent a code to you, dont forget to check your spam",
type: "success"
}).then(function() {
window.location = "verify-user.php ";
});
});
</script>
';
exit();
}
else{
echo '
<script type="text/javascript">
$(document).ready(function(){
swal({
title: "Error!",
text: "We cannot log you in again, you already voted",
type: "error"
}).then(function() {
window.location = "index.php";
});
});
</script>
';
exit();
}
}
}
else
{
echo '
<script type="text/javascript">
$(document).ready(function(){
swal({
title: "Error!",
text: "Please enter valid details",
type: "error"
}).then(function() {
window.location = "index.php";
});
});
</script>
';
exit();
}
}
?>