/
index.php
2487 lines (2148 loc) · 86.6 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
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
session_start();
//////////////////////////////////////////////////////////////////////////
// Public Controller
//
// Includes
// Start Code
// Badge Purchases
// Logging In/Out
// Password Reset Generation
// Password Reset Code Entry
// My Account
// My Personal Info
// Registration
// Schedule
// Con Store
// Forums
// Guests
// Static Pages
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////
$siteroot = '/home/simpleco/';
require $siteroot . 'demo2/app/includes_php/magicquotes.inc.php';
require $siteroot . 'demo2/app/includes_php/encrypt.inc.php';
require $siteroot . 'demo2/app/includes_php/access.inc.php';
require $siteroot . 'demo2/app/includes_php/db.inc.php';
require $siteroot . 'demo2/app/includes_php/functions.inc.php';
require $siteroot . 'demo2/app/stripe-php/lib/Stripe.php';
$includemailer = $siteroot . 'demo2/app/PHPMailer_5.2.2/*.php';
foreach (glob($includemailer) as $filename)
{
include $filename;
}
//////////////////////////////////////////////////////////////////////////
// Arrays Used Across Entire Controller
//////////////////////////////////////////////////////////////////////////
$con_info = getCurrentYearInfo();
$user_info = getUserInfo();
//////////////////////////////////////////////////////////////////////////
// Badge Purchases
//////////////////////////////////////////////////////////////////////////
// regular badge purchase
if (isset($_GET['buybadge'])) {
if (isset($_POST['stripeToken'])) {
// check to see if session is set
if (!isset($_SESSION['loggedIn'])) {
$title = 'Please Log In';
$longdesc = "You need to log in to buy a badge.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// charge the card
Stripe::setApiKey("sk_test_y4j5rHbNnOXWIgtsMbQUvWFh");
$token = $_POST['stripeToken'];
$description = $_SESSION['email'] . ' bought badge';
$charge = Stripe_Charge::create(array(
"amount" => $con_info['badge_price'],
"currency" => "usd",
"card" => $token,
"description" => $description));
// record that the user paid in lookup_users_years
$sql = 'INSERT INTO lookup_users_years SET
userID = :userID,
yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
// log the action
logevent($user_info['id'], NULL, 'paid for badge');
// convert the stored badge price in cents w/o formatting to a formatted string
setlocale(LC_MONETARY, 'en_US');
$price = money_format('%.2n', $con_info['badge_price']/100);
// send receipt email
$address = $_SESSION['email'];
$subject = "Convention Badge Receipt";
$body = '<html><body><p>Thank you for purchasing a badge for the convention ' .
'in the amount of ' . $price . '.</p>' .
'<p></p></body></html>';
include $siteroot . 'demo2/app/includes_php/send_mail.php';
// show confirmation
$title = "Badge Purchased";
$longdesc = 'You have purchased a badge for ' . $user_info['first_name'] . ' ' .
$user_info['last_name'] . ' in the amount of ' . $price . '. A receipt was emailed to ' . $user_info['email'] . '.';
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
// if badges are not currently being sold, direct the user to a message
if ($con_info['allow_badges'] == 0) {
$title = 'Badges Are Not Currently For Sale';
$longdesc = "Badges are not currently for sale.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// check to see if session is set
if (!isset($_SESSION['loggedIn'])) {
$title = 'Please Log In';
$longdesc = "You need to log in to buy a badge.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// checks to see if the user has already bought a badge for current year
$sql = 'SELECT COUNT(*) FROM lookup_users_years
WHERE userID = :userID AND yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
$paidforbadge = $s->fetch();
// convert the stored badge price in cents w/o formatting to a formatted string
setlocale(LC_MONETARY, 'en_US');
$price = money_format('%.2n', $con_info['badge_price']/100);
$kidprice = money_format('%.2n', $con_info['kid_badge_price']/100);
// display form
include $siteroot . 'demo2/app/pages_public/buy_badge.inc.html.php';
exit();
}
// show all badge purchases & allows registration of kids and purchase of kid badges
if (isset($_GET['mybadges'])) {
if (isset($_POST['stripeToken'])) {
// check to see if session is set
if (!isset($_SESSION['loggedIn'])) {
$title = 'Please Log In';
$longdesc = "You need to log in to buy a badge.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// make sure a child is selected
if (!$_POST['childID']) {
$title = 'No Child Selected';
$longdesc = "Please select a child for a badge.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// if kid badge is on, use that price; if kid badge is off, use full price
if ($con_info['kid_badge_on'] == 0) {
$amount_to_charge = $con_info['badge_price'];
}
else {
$amount_to_charge = $con_info['kid_badge_price'];
}
// charge the card
Stripe::setApiKey("sk_test_y4j5rHbNnOXWIgtsMbQUvWFh");
$token = $_POST['stripeToken'];
$description = $_SESSION['email'] . ' bought child badge';
$charge = Stripe_Charge::create(array(
"amount" => $amount_to_charge,
"currency" => "usd",
"card" => $token,
"description" => $description));
// record that the child has a badge
$sql = 'INSERT INTO lookup_users_years SET
userID = :userID,
yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $_POST['childID']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
// log the action
logevent($user_info['id'], NULL, 'paid for badge for child with id ' . $_POST['childID']);
// convert the stored badge price in cents w/o formatting to a formatted string
setlocale(LC_MONETARY, 'en_US');
$price_in_email = money_format('%.2n', $amount_to_charge/100);
// send receipt email
$address = 'lintonrentfro@gmail.com';
$subject = "Convention Badge Receipt";
$body = '<html><body><p>Thank you for purchasing a child badge for the convention ' .
'in the amount of ' . $price_in_email . '.</p>' .
'<p></p></body></html>';
include $siteroot . 'demo2/app/includes_php/send_mail.php';
// show confirmation
$title = "Badge Purchased";
$longdesc = 'You have purchased a child badge in the amount of ' . $price_in_email . '. A receipt was emailed to lintonrentfro@gmail.com.';
$longdesc .= '<p><a href="/?mybadges">return to your convention badges</a></p>';
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
if (isset($_POST['action']) and $_POST['action'] == 'free_badge') {
// record that the child has a badge
$sql = 'INSERT INTO lookup_users_years SET
userID = :userID,
yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $_POST['childID']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
header("Location: ." . '?mybadges');
exit();
}
// check to see if session is set
if (!isset($_SESSION['loggedIn'])) {
$title = 'Please Log In';
$longdesc = "You need to log in to view your badge purchase information.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// checks to see if the user has already bought a badge for current year
$sql = 'SELECT COUNT(*) FROM lookup_users_years
WHERE userID = :userID AND yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
$paidforbadge = $s->fetch();
if ($paidforbadge['COUNT(*)'] == 1) {
$primary_user_badge_status = '<i class="icon-ok icon-white"></i>';
}
if ($paidforbadge['COUNT(*)'] != 1) {
$primary_user_badge_status = '<a href="?buybadge">buy</a>';
}
// gets all kids under this user
$sql = '
SELECT first_name, last_name, id
FROM users
WHERE parentID = :parentID';
$s = $pdo->prepare($sql);
$s->bindValue(':parentID', $user_info['id']);
$s->execute();
$kids = $s->fetchall(PDO::FETCH_ASSOC);
// build an array of those kids' ids and a badge status of 1 or 0
foreach ($kids as $kid):
$sql = 'SELECT COUNT(*) FROM lookup_users_years
WHERE userID = :userID AND yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $kid['id']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
$result = $s->fetch(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$badges[] = array(
'id' => $kid['id'],
'badge' => $row['COUNT(*)']);
}
endforeach;
// build a final array of kids ids, names, and badge status
$kids_with_badge_status = array();
foreach ($kids as $kid):
foreach ($badges as $badge):
if (($kid['id'] == $badge['id']) and ($badge['badge'] == 1)) {
$kids_with_badge_status[] = array('id' => $kid['id'], 'first_name' => $kid['first_name'], 'last_name' => $kid['last_name'], 'badge_status' => '<i class="icon-ok icon-white"></i>');
}
if (($kid['id'] == $badge['id']) and ($badge['badge'] == 0)) {
$kids_with_badge_status[] = array('id' => $kid['id'], 'first_name' => $kid['first_name'], 'last_name' => $kid['last_name'], 'badge_status' => 'no badge');
}
endforeach;
endforeach;
// format prices
setlocale(LC_MONETARY, 'en_US');
$price = money_format('%.2n', $con_info['badge_price']/100);
$kidprice = money_format('%.2n', $con_info['kid_badge_price']/100);
// create age range strings for use in the html page
if (($con_info['kid_badge_on'] == 1) and ($con_info['free_badge_on'] == 1)) {
$kid_badge_age_range = $con_info['free_badge_max_age'] + 1 . '-' . $con_info['kid_badge_max_age'];
}
if (($con_info['kid_badge_on'] == 1) and ($con_info['free_badge_on'] == 0)) {
$kid_badge_age_range = 'Under ' . $con_info['kid_badge_max_age'];
}
include $siteroot . 'demo2/app/pages_public/mybadges.inc.html.php';
exit();
}
// add a child to a user's account
if (isset($_POST['action']) and $_POST['action'] == 'add_kid') {
// check to see if userIP is banned
if (isIPBanned() == TRUE) {
$title = "Your IP Address Has Been Banned";
$longdesc = "Your ip was banned from logging into this website,
registering a new account, or recovering a password. If you feel
this is a mistake, please contact the convention staff for
assistance.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// checks to see if all required fields are set
if (!isset($_POST['first_name'])
or !isset($_POST['last_name'])) {
$title = "Error";
$longdesc = 'Please fill out all required fields.';
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
// gets parent info
$sql = 'SELECT * FROM users WHERE id = :id';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $_POST['parentID']);
$s->execute();
$parent_info = $s->fetch();
// create a random login and password
$login = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
$passwordtext = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
// create new user row
$sql = '
INSERT INTO users
SET
address1 = :address1,
address2 = :address2,
city = :city,
state = :state,
zip = :zip,
first_name = :first_name,
last_name = :last_name,
verified = :verified,
email = :email,
parentID = :parentID';
$s = $pdo->prepare($sql);
$s->bindValue(':first_name', $_POST['first_name']);
$s->bindValue(':last_name', $_POST['last_name']);
$s->bindValue(':parentID', $parent_info['id']);
$s->bindValue(':address1', $parent_info['address1']);
$s->bindValue(':address2', $parent_info['address2']);
$s->bindValue(':city', $parent_info['city']);
$s->bindValue(':state', $parent_info['state']);
$s->bindValue(':zip', $parent_info['zip']);
$s->bindValue(':verified', '1');
$s->bindValue(':email', $login);
$s->execute();
// adds password hash
$salt = generateSalt($login);
$password = generateHash($salt, $passwordtext);
$sql = 'UPDATE users SET
password = :password
WHERE email = :email';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $login);
$s->bindValue(':password', $password);
$s->execute();
// get the user id
$id = userID($login);
// add user role of 1
$sql = 'INSERT INTO lookup_users_userroles (userID, roleID) VALUES
(:id, 1)';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $id);
$s->execute();
// send email with login/password for child
$address = 'lintonrentfro@gmail.com';
$subject = "Child Account Created";
$body = '<html><body><p>You have created an account for your child on the convention website.</p>' .
'<p>Your child can log in to the convention website and register for events if you give them this login and password. They will not have access to the forums or your account info.</p>' .
'<p>login: ' . $login . '</p><p>password: ' . $passwordtext . '</p><p>If you do not want your child to register for events, do not give them the login and password.</p></body></html>';
require $siteroot . 'demo2/app/includes_php/send_mail.php';
header("Location: ." . '?mybadges');
exit();
}
//////////////////////////////////////////////////////////////////////////
// logging in/out
//////////////////////////////////////////////////////////////////////////
// responds to request to login and sends login form
if (isset($_GET['loginform'])) {
include $siteroot . 'demo2/app/pages_public/login.inc.html.php';
exit();
}
// takes login form data and checks it against database
if (isset($_GET['loginformdata'])){
// check to see if userIP is banned
if (isIPBanned() == TRUE) {
$title = "Your IP Address Has Been Banned";
$longdesc = "Your ip was banned from logging into this website,
registering a new account, or recovering a password. If you feel
this is a mistake, please contact the convention staff for
assistance.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// For each previous failed login attempt, the wait time until another
// attempt can be made doubles. The wait time begins with 2 seconds.
if (isUserInLoginWaitingPeriod($_POST['email']) == TRUE) {
$title = "Too Many Unsuccessful Login Attempts";
$longdesc = "For each failed login attempt, the wait time until another
attempt can be made doubles. Please wait a moment and try again or
use the password recovery tool.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
if (userIsLoggedIn()) {
// get the user id
$id = userID($_SESSION['email']);
// log the action
logevent($id, NULL, 'good login');
// reset the failed_logins field
recordGoodLogin($id);
// return to the previous page
header("Location: .");
exit();
}
else {
// get the user id
$id = userID($_POST['email']);
// log the action
logevent($id, NULL, 'bad login');
// add to the failed_logins field
recordBadLogin($id);
// display error
$title = "Incorrect Login";
$longdesc = "That email/password combination does not belong to a
registered user or you have not verified your email address yet.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
}
// responds to logout attempt
if (isset($_GET['logout'])) {
// get the user id
$id = userID($_SESSION['email']);
// log the action
logevent($id, NULL, 'logout');
// logout
unset($_SESSION['loggedIn']);
unset($_SESSION['email']);
unset($_SESSION['password']);
header("Location: index.php");
exit();
}
//////////////////////////////////////////////////////////////////////////
// password reset code generation
//////////////////////////////////////////////////////////////////////////
if (isset($_GET['forgot_password'])) {
include $siteroot . 'demo2/app/pages_public/lost_password.inc.html.php';
exit ();
}
// responds to lost password form
if (isset($_POST['action']) and $_POST['action'] == 'lost_password_form') {
// check to see if userIP is banned
if (isIPBanned() == TRUE) {
$title = "Your IP Address Has Been Banned";
$longdesc = "Your ip was banned from logging into this website,
registering a new account, or recovering a password. If you feel
this is a mistake, please contact the convention staff for
assistance.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// check to see if posted email belongs to a registered user
$sql = 'SELECT COUNT(*)
FROM users
WHERE email = :email';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $_POST['email']);
$s->execute();
$result = $s->fetch();
// if no matching email address is found
if ($result['COUNT(*)'] < 1) {
// log the action
logevent(NULL, NULL, 'bad email for password recovery');
// get user IP
$userIP = $_SERVER['REMOTE_ADDR'];
// get current time
$current_time = date('Y-m-d H:i:s');
// calculate time 24 hours ago
$one_day_ago = date('Y-m-d H:i:s', strtotime($current_time . ' - 1 days'));
// get number of guesses made from same IP in last 24 hours
$sql = 'SELECT COUNT(*)
FROM log
WHERE userIP = :userIP AND time > :time AND action = :action';
$s = $pdo->prepare($sql);
$s->bindValue(':userIP', $userIP);
$s->bindValue(':time', $one_day_ago);
$s->bindValue(':action', 'bad email for password recovery');
$s->execute();
$attempts = $s->fetch();
// if guesses in last 24 hours are > 10, block further attempts from IP
if ($attempts['COUNT(*)'] > 10) {
// log the action
logevent(NULL, NULL, 'ip banned');
// display error message
$title = "Your IP Address Has Been Banned";
$longdesc = "We have detected more than 10 attempts from your IP to
recover passwords for email addresses not found in our system
during the previous 24 hours. Your IP address is now banned from
logging into this website, recovering a password, or registering
a new account. If you feel this is a mistake, please contact
the convention staff for assistance.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// display error message
$title = "Email Address Not Found";
$longdesc = "That email address does not belong to a registered user.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// check to see if recovery code already exists for user
$sql = 'SELECT COUNT(*)
FROM password_recovery
WHERE email = :email';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $_POST['email']);
$s->execute();
$result = $s->fetch();
// if recovery code already exists
if ($result['COUNT(*)'] > 0) {
// get the recovery code's expiration
$sql = 'SELECT expires_on
FROM password_recovery
WHERE email = :email';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $_POST['email']);
$s->execute();
$expires_on = $s->fetch();
// if the expiration is greater than the current time, delete that row
if (date('Y-m-d H:i:s') > $expires_on['expires_on']) {
$sql = 'DELETE FROM password_recovery
WHERE email = :email';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $_POST['email']);
$s->execute();
}
// if the expiration still has some time left, display message
$title = "Recovery Email Already Sent";
$longdesc = "A password recovery email has already been sent to you.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// insert password recovery row into table
$recovery_string = generateRandom32CharString();
$created_time = date('Y-m-d H:i:s');
$created_ip = $_SERVER['REMOTE_ADDR'];
$expires_on = date('Y-m-d H:i:s', strtotime($created_time . ' + 1 days'));
$sql = 'INSERT INTO password_recovery
SET email = :email,
recovery_string = :recovery_string,
created_time = :created_time,
created_ip = :created_ip,
expires_on = :expires_on';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $_POST['email']);
$s->bindValue(':recovery_string', $recovery_string);
$s->bindValue(':created_time', $created_time);
$s->bindValue(':created_ip', $created_ip);
$s->bindValue(':expires_on', $expires_on);
$s->execute();
// get the user id
$id = userID($_POST['email']);
// log the action
logevent($id, NULL, 'password recovery created');
// send recovery email
$address = 'lintonrentfro@gmail.com';
// $address = $_POST['email'];
$subject = "Password Reset";
$body = '<html><body><p>Click this link and paste the reset code below into
the form provided.</p>' . '<p>
<a href="localhost/index.php?reset_password">
click</a></p>' . $recovery_string . '</body></html>';
require $siteroot . 'demo2/app/includes_php/send_mail.php';
// display confirmation
$title = "Recovery Email Sent";
$longdesc = "Check your email. You should receive a message that will tell
you how to reset your password. This must be done within 24 hours.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
//////////////////////////////////////////////////////////////////////////
// password reset code entry
//////////////////////////////////////////////////////////////////////////
if (isset($_GET['reset_password'])) {
include $siteroot . 'demo2/app/pages_public/enter_code.inc.html.php';
exit ();
}
// checks code
if (isset($_POST['action']) and $_POST['action'] == 'password_recovery') {
// check to see if userIP is banned
if (isIPBanned() == TRUE) {
$title = "Your IP Address Has Been Banned";
$longdesc = "Your ip was banned from logging into this website,
registering a new account, or recovering a password. If you feel
this is a mistake, please contact the convention staff for
assistance.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// check to see if this is a valid code
$sql = 'SELECT COUNT(*)
FROM password_recovery
WHERE recovery_string = :recovery_string';
$s = $pdo->prepare($sql);
$s->bindValue(':recovery_string', $_POST['recovery_code']);
$s->execute();
$result = $s->fetch();
// if code does not exist
if ($result['COUNT(*)'] < 1) {
$title = "Recovery Code Not Found";
$longdesc = "Did you type/paste that code correctly? No such code was
found.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// get the row for that code
$sql = 'SELECT *
FROM password_recovery
WHERE recovery_string = :recovery_string';
$s = $pdo->prepare($sql);
$s->bindValue(':recovery_string', $_POST['recovery_code']);
$s->execute();
$code_info = $s->fetch();
// if code is expired, delete row and display message
if (date('Y-m-d H:i:s') > $code_info['expires_on']) {
$sql = 'DELETE FROM password_recovery
WHERE recovery_string = :recovery_string';
$s = $pdo->prepare($sql);
$s->bindValue(':recovery_string', $_POST['recovery_code']);
$s->execute();
$title = "Recovery Code Expired";
$longdesc = "That password recovery code has expired. They only last 24
hours.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// if code has not expired, provide form to reset password
if (date('Y-m-d H:i:s') < $code_info['expires_on']) {
$email = $code_info['email'];
$recovery_string = $_POST['recovery_code'];
include $siteroot . 'demo2/app/pages_public/reset_password.inc.html.php';
exit ();
}
}
// reset password
if (isset($_POST['action']) and $_POST['action'] == 'reset_password') {
// check to see if userIP is banned
if (isIPBanned() == TRUE) {
$title = "Your IP Address Has Been Banned";
$longdesc = "Your ip was banned from logging into this website,
registering a new account, or recovering a password. If you feel
this is a mistake, please contact the convention staff for
assistance.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// if both password fields aren't the same
if ($_POST['password'] != $_POST['password2']) {
$title = "Error";
$longdesc = 'The passwords did not match.';
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
// delete password recovery code's row
$sql = 'DELETE FROM password_recovery
WHERE recovery_string = :recovery_string';
$s = $pdo->prepare($sql);
$s->bindValue(':recovery_string', $_POST['recovery_string']);
$s->execute();
// set new password for user
$salt = generateSalt($_POST['email']);
$password = generateHash($salt, $_POST['password']);
$sql = 'UPDATE users SET
password = :password
WHERE email = :email';
$s = $pdo->prepare($sql);
$s->bindValue(':email', $_POST['email']);
$s->bindValue(':password', $password);
$s->execute();
// get the user id
$id = userID($_POST['email']);
// log the action
logevent($id, NULL, 'password reset');
// display confirmation
$title = "Password Reset";
$longdesc = "Your password has been reset.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
//////////////////////////////////////////////////////////////////////////
// my schedule
//////////////////////////////////////////////////////////////////////////
if (isset($_GET['myschedule'])) {
// if schedule should not be shown, user directed to a message
if ($con_info['schedule_shown'] == 0) {
$title = 'Not Available Yet';
$longdesc = "When event registration begins, this is where you'll find
your schdule. It will show the events you've signed up for, the
status of any events you're running, and any convention duties you
have if you're part of the convention staff.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
// check to see if session is set
if (!isset($_SESSION['loggedIn'])) {
if (!isset($_SESSION['loggedIn'])) {
$title = 'Please Log In';
$longdesc = "You need to log in to view your convention schedule.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
}
// gets events the user is running
$sql = 'SELECT *
FROM events
WHERE contact = :contact';
$s = $pdo->prepare($sql);
$s->bindValue(':contact', $user_info['id']);
$s->execute();
$result = $s->fetchall();
foreach ($result as $row) {
$events_running[] = array(
'id' => $row['id'],
'name' => $row['name'],
'building' => $row['building'],
'room' => $row['room'],
'start' => $row['start'],
'end' => $row['end'],
'type' => $row['type'],
'currentusers' => $row['currentusers'],
'maxusers' => $row['maxusers'],
'status' => $row['status']);
}
// gets number of events user is running
$sql = 'SELECT COUNT(*) FROM events
WHERE contact = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$eventsrunningnumber = $s->fetch();
// gets if the user has paid for a badge or not
$sql = 'SELECT COUNT(*) FROM lookup_users_years
WHERE userID = :userID AND yearID = :yearID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->bindValue(':yearID', $con_info['current_year']);
$s->execute();
$paidforbadge = $s->fetch();
// gets events for which the user is registered
$sql = 'SELECT id, name, start, end, building, room, currentusers, maxusers,
type, registration_required, can_conflict
FROM lookup_users_events
INNER JOIN events ON eventID = id
WHERE userID = :userID
ORDER BY start ASC';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$result = $s->fetchall();
foreach ($result as $row) {
$events_registered[] = array(
'id' => $row['id'],
'name' => $row['name'],
'building' => $row['building'],
'room' => $row['room'],
'start' => $row['start'],
'end' => $row['end'],
'type' => $row['type'],
'currentusers' => $row['currentusers'],
'maxusers' => $row['maxusers'],
'registration_required' => $row['registration_required']);
}
// gets number of events for which user is registered
$sql = 'SELECT COUNT(*) FROM lookup_users_events
WHERE userID = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$eventsregisterednumber = $s->fetch();
// gets events for which the user is a helper
$sql = 'SELECT duty_roster.start, duty_roster.end, events.name,
events.building, events.room, events.id, duty_roster.description
FROM duty_roster
INNER JOIN events
ON duty_roster.eventID = events.id
WHERE duty_roster.userID = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$result = $s->fetchall();
foreach ($result as $row) {
$events_helper[] = array(
'events.id' => $row['id'],
'events.name' => $row['name'],
'events.building' => $row['building'],
'events.room' => $row['room'],
'duty_roster.start' => $row['start'],
'duty_roster.description' => $row['description'],
'duty_roster.end' => $row['end']);
}
// gets number of duty roster items for this user
$sql = 'SELECT COUNT(*) FROM duty_roster
WHERE userID = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$eventshelpernumber = $s->fetch();
// check if user is a guest
$sql = 'SELECT COUNT(*) FROM guests
WHERE userID = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$user_is_guest_or_not = $s->fetch();
// get all info for events on schedule for guest
$sql = '
SELECT *
FROM lookup_guests_events
INNER JOIN events
ON eventID = events.id
WHERE userID = :userID and events.status = "on schedule - all clear"
ORDER BY start ASC';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$events_as_guest = $s->fetchall(PDO::FETCH_ASSOC);
include $siteroot . 'demo2/app/pages_public/myschedule.inc.html.php';
exit();
}
//////////////////////////////////////////////////////////////////////////
// my personal info
//////////////////////////////////////////////////////////////////////////
if (isset($_GET['mypersonalinfo'])) {
// check to see if session is set
if (!isset($_SESSION['loggedIn'])) {
$title = 'Please Log In';
$longdesc = "You need to log in to view your account information.";
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit ();
}
// check if user is a guest
$sql = 'SELECT COUNT(*) FROM guests
WHERE userID = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$user_is_guest_or_not = $s->fetch();
// get guest info for user
$sql = 'SELECT * FROM guests WHERE userID = :userID';
$s = $pdo->prepare($sql);
$s->bindValue(':userID', $user_info['id']);
$s->execute();
$guest_info = $s->fetch(PDO::FETCH_ASSOC);
include $siteroot . 'demo2/app/pages_public/mypersonalinfo.inc.html.php';
exit();
}
// responds to request to update guest info
if (isset($_POST['action']) and $_POST['action'] == 'update_guest_info') {
$sql = '
UPDATE guests
SET
short_description = :short_description,
full_description = :full_description,
professional_name = :professional_name
WHERE
guestID = :guestID
LIMIT 1';
$s = $pdo->prepare($sql);
$s->bindValue(':short_description', $_POST['short_description']);
$s->bindValue(':full_description', $_POST['full_description']);
$s->bindValue(':professional_name', $_POST['professional_name']);
$s->bindValue(':guestID', $_POST['guestID']);
$s->execute();
// display confirmation
$title = "Guest Information Updated";
$longdesc = 'You have successfully updated your guest information';
include $siteroot . 'demo2/app/pages_public/confirmation.inc.html.php';
exit();
}
// responds to request from user to update own info
if (isset($_POST['action']) and $_POST['action'] == 'update_myuserinfo') {
try {
$sql = 'UPDATE users SET
first_name = :first_name,
last_name = :last_name,
company = :company,
email = :email,
address1 = :address1,
address2 = :address2,
city = :city,
state = :state,
zip = :zip,
home = :home,