-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.php
624 lines (522 loc) · 23.4 KB
/
function.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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<?php
function checkUser($email)
{
global $con;
$query = mysqli_query($con, "SELECT email FROM users WHERE email = '$email'");
if(mysqli_num_rows($query) > 0)
{
return 'true';
}else
{
return 'false';
}
}
function UserID($email)
{
global $con;
$query = mysqli_query($con, "SELECT id FROM users WHERE email = '$email'");
$row = mysqli_fetch_assoc($query);
return $row['id'];
}
function generateRandomString($length = 20) {
// This function has taken from stackoverflow.com
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return md5($randomString);
}
function send_mail($to, $token)
{
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'outlook.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = '[email protected]';
$mail->FromName = 'Ogiebooks';
$mail->addAddress($to);
$mail->addReplyTo('[email protected]', 'Reply');
$mail->isHTML(true);
$mail->Subject = 'Ogiebooks: Password Recovery Instruction';
$link = 'http://ogiebooks.gq/forget.php?email='.$to.'&token='.$token;
//Body of the mail
$mail->Body = <<< EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple Transactional Email</title>
</head>
<body>
<!-- / Full width container -->
<table class="full-width-container" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" bgcolor="#eeeeee" style="width: 100%; height: 100%; padding: 30px 0 30px 0;">
<tr>
<td align="center" valign="top">
<!-- / 700px container -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="700" bgcolor="#ffffff" style="width: 700px;">
<tr>
<td align="center" valign="top">
<!-- / Header -->
<table class="container header" border="0" cellpadding="0" cellspacing="0" width="620" style="width: 620px;">
<tr>
<td style="padding: 30px 0 30px 0; border-bottom: solid 1px #eeeeee;" align="left">
<a href="#" style="font-size: 30px; text-decoration: none; color: #000000;">Ogiebooks</a>
</td>
</tr>
</table>
<!-- /// Header -->
<!-- / Hero subheader -->
<table class="container hero-subheader" border="0" cellpadding="0" cellspacing="0" width="620" style="width: 620px;">
<tr>
<td class="hero-subheader__title" style="font-size: 43px; font-weight: bold; padding: 80px 0 15px 0;" align="left">Reset Password</td>
</tr>
<tr>
<td class="hero-subheader__content" style="text-align: justify; font-size: 16px; line-height: 27px; color: #969696; padding: 0 0 25px 0;" align="left">We are deeply sorry you are having issues signing in to your account, therefore we would like to assist you to regain access access as soon as possible. Please kindly click the button below to reset your password. Please do not hesitate to contact us if you ran into issues and we would gladly assist you. Have a nice day ahead.</td>
</tr>
</table>
<!-- /// Hero subheader -->
<!-- / CTA Block -->
<table class="container cta-block" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" valign="top">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" style="width: 620px;">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="cta-block__button" width="230" align="center" style="width: 200px;">
<a href="http://ogiebooks.gq/forget.php?email=$to&token=$token" style="border: 3px solid #eeeeee; color: #969696; text-decoration: none; padding: 15px 45px; text-transform: uppercase; display: block; text-align: center; font-size: 16px;">Reset Password</a>
</td>
</tr>
<tr>
<td class="cta-block__content" style="padding: 20px 0 27px 0; font-size: 16px; line-height: 27px; color: #969696; text-align: center;">Just in case it doesn't work, here's the same link so you could copy and paste it into your browser. <br /><br /><a href="http://ogiebooks.gq/forget.php?email=$to&token=$token">http://ogiebooks.gq/forget.php?email=$to&token=$token</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// CTA Block -->
<!-- / Divider -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" style="padding-top: 25px;" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="border-bottom: solid 1px #eeeeee; width: 620px;">
<tr>
<td align="center"> </td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Divider -->
<!-- / Info Bullets -->
<table class="container info-bullets" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="width: 620px;">
<tr>
<td class="info-bullets__block" style="padding: 30px 30px 15px 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img13.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">[email protected]</td>
</tr>
</table>
</td>
<td class="info-bullets__block" style="padding: 30px 30px 15px 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img11.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">N.A.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="info-bullets__block" style="padding: 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img12.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">Kota Kinabalu, Sabah</td>
</tr>
</table>
</td>
<td class="info-bullets__block" style="padding: 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img12.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">Malaysia</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Info Bullets -->
<!-- / Social nav -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="border-top: 1px solid #eeeeee; width: 620px;">
<tr>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img7.png" border="0">
</a>
</td>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img8.png" border="0">
</a>
</td>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img9.png" border="0">
</a>
</td>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img10.png" border="0">
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Social nav -->
<!-- / Footer -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="border-top: 1px solid #eeeeee; width: 620px;">
<tr>
<td style="text-align: center; padding: 50px 0 10px 0;">
<a href="#" style="font-size: 28px; text-decoration: none; color: #d5d5d5;">Ogiebooks</a>
</td>
</tr>
<tr>
<td align="middle">
<table width="60" height="2" border="0" cellpadding="0" cellspacing="0" style="width: 60px; height: 2px;">
<tr>
<td align="middle" width="60" height="2" style="background-color: #eeeeee; width: 60px; height: 2px; font-size: 1px;"><img src="http://dev2.slicejack.com/portfolio-email/img/img16.jpg"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="color: #d5d5d5; text-align: center; font-size: 15px; padding: 10px 0 60px 0; line-height: 22px;">Copyright © 2017 <a href="http://slicejack.com/" target="_blank" style="text-decoration: none; border-bottom: 1px solid #d5d5d5; color: #d5d5d5;">Ogiebooks</a>. <br />A 2nd hand book selling website made by STTSS students, for STTSS students <br />All rights reserved.</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Footer -->
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
EOF;
//Altbody is used to display plain text message for those email viewers which are not HTML compatible
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
if(!$mail->send()) {
return 'fail';
} else {
return 'success';
}
}
function send_verification_mail($to, $key)
{
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.yandex.ru';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'outlook.com';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = '[email protected]';
$mail->FromName = 'Ogiebooks';
$mail->addAddress($to);
$mail->addReplyTo('[email protected]', 'Reply');
$mail->isHTML(true);
$mail->Subject = 'Ogiebooks: Sign Up Verification Email';
//Body of the mail
$mail->Body = <<< EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple Transactional Email</title>
</head>
<body>
<!-- / Full width container -->
<table class="full-width-container" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" bgcolor="#eeeeee" style="width: 100%; height: 100%; padding: 30px 0 30px 0;">
<tr>
<td align="center" valign="top">
<!-- / 700px container -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="700" bgcolor="#ffffff" style="width: 700px;">
<tr>
<td align="center" valign="top">
<!-- / Header -->
<table class="container header" border="0" cellpadding="0" cellspacing="0" width="620" style="width: 620px;">
<tr>
<td style="padding: 30px 0 30px 0; border-bottom: solid 1px #eeeeee;" align="left">
<a href="#" style="font-size: 30px; text-decoration: none; color: #000000;">Ogiebooks</a>
</td>
</tr>
</table>
<!-- /// Header -->
<!-- / Hero subheader -->
<table class="container hero-subheader" border="0" cellpadding="0" cellspacing="0" width="620" style="width: 620px;">
<tr>
<td class="hero-subheader__title" style="font-size: 43px; font-weight: bold; padding: 80px 0 15px 0;" align="left">Verification Email</td>
</tr>
<tr>
<td class="hero-subheader__content" style="text-align: justify; font-size: 16px; line-height: 27px; color: #969696; padding: 0 0 25px 0;" align="left">Before anything, we would like to thank you for showing your support by signing up. We hope you would have a pleasant experience when using our service and please do not hesitate to contact us if you have any enquiries or ran into any issues. Have a nice day ahead.</td>
</tr>
</table>
<!-- /// Hero subheader -->
<!-- / CTA Block -->
<table class="container cta-block" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" valign="top">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" style="width: 620px;">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="cta-block__button" width="230" align="center" style="width: 200px;">
<a href="http://ogiebooks.gq/confirm.php?key=$key" style="border: 3px solid #eeeeee; color: #969696; text-decoration: none; padding: 15px 45px; text-transform: uppercase; display: block; text-align: center; font-size: 16px;">Activate Account</a>
</td>
</tr>
<tr>
<td class="cta-block__content" style="padding: 20px 0 27px 0; font-size: 16px; line-height: 27px; color: #969696; text-align: center;">Just in case it doesn't work, here's the same link so you could copy and paste it into your browser. <br /><br /><a href="http://ogiebooks.gq/confirm.php?key=$key">http://ogiebooks.gq/confirm.php?key=$key</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// CTA Block -->
<!-- / Divider -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" style="padding-top: 25px;" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="border-bottom: solid 1px #eeeeee; width: 620px;">
<tr>
<td align="center"> </td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Divider -->
<!-- / Info Bullets -->
<table class="container info-bullets" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="width: 620px;">
<tr>
<td class="info-bullets__block" style="padding: 30px 30px 15px 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img13.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">[email protected]</td>
</tr>
</table>
</td>
<td class="info-bullets__block" style="padding: 30px 30px 15px 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img11.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">N.A.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="info-bullets__block" style="padding: 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img12.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">Kota Kinabalu, Sabah</td>
</tr>
</table>
</td>
<td class="info-bullets__block" style="padding: 30px;" align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="info-bullets__icon" style="padding: 0 15px 0 0;">
<img src="http://dev2.slicejack.com/portfolio-email/img/img12.png">
</td>
<td class="info-bullets__content" style="color: #969696; font-size: 16px;">Malaysia</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Info Bullets -->
<!-- / Social nav -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="border-top: 1px solid #eeeeee; width: 620px;">
<tr>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img7.png" border="0">
</a>
</td>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img8.png" border="0">
</a>
</td>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img9.png" border="0">
</a>
</td>
<td align="center" style="padding: 30px 0 30px 0;">
<a href="#">
<img src="http://dev2.slicejack.com/portfolio-email/img/img10.png" border="0">
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Social nav -->
<!-- / Footer -->
<table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td align="center">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="620" align="center" style="border-top: 1px solid #eeeeee; width: 620px;">
<tr>
<td style="text-align: center; padding: 50px 0 10px 0;">
<a href="#" style="font-size: 28px; text-decoration: none; color: #d5d5d5;">Ogiebooks</a>
</td>
</tr>
<tr>
<td align="middle">
<table width="60" height="2" border="0" cellpadding="0" cellspacing="0" style="width: 60px; height: 2px;">
<tr>
<td align="middle" width="60" height="2" style="background-color: #eeeeee; width: 60px; height: 2px; font-size: 1px;"><img src="http://dev2.slicejack.com/portfolio-email/img/img16.jpg"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="color: #d5d5d5; text-align: center; font-size: 15px; padding: 10px 0 60px 0; line-height: 22px;">Copyright © 2017 <a href="http://slicejack.com/" target="_blank" style="text-decoration: none; border-bottom: 1px solid #d5d5d5; color: #d5d5d5;">Ogiebooks</a>. <br />A 2nd hand book selling website made by STTSS students, for STTSS students <br />All rights reserved.</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- /// Footer -->
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
EOF;
//Altbody is used to display plain text message for those email viewers which are not HTML compatible
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
if(!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit();
} else {
return 'success';
}
}
function send_verification_change_mail($to, $key2, $id)
{
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'outlook.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = '[email protected]';
$mail->FromName = 'Ogiebooks';
$mail->addAddress($to);
$mail->addReplyTo('[email protected]', 'Reply');
$mail->isHTML(true);
$mail->Subject = 'Ogiebooks: Email Change Verification';
$link = 'http://ogiebooks.gq/login/changeemail.php?email='.$to.'&key='.$key2.'&id='.$id;
$mail->Body = "Thank you for signing up.<br> Please verify your email by clicking the below link. <br><i>". $link."</i>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
return 'fail';
} else {
return 'success';
}
}
function verifytoken($userID, $token)
{
global $con;
$query = mysqli_query($con, "SELECT valid FROM recovery_keys WHERE userID = $userID AND token = '$token'");
$row = mysqli_fetch_assoc($query);
if(mysqli_num_rows($query) > 0)
{
if($row['valid'] == 1)
{
return 1;
}else
{
return 0;
}
}else
{
return 0;
}
}
?>