1 | <?php |
---|
2 | require 'classes/master.php'; //should be at top of every page |
---|
3 | |
---|
4 | /* Page still has ambiguous design. Login and Register buttons are at same hierarchy level, makes user suspect the register button works based on input given here. |
---|
5 | * Instead redirects to anoter page. |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | $errorMessage[] = ""; |
---|
10 | |
---|
11 | if (isset($_POST['register'])) { |
---|
12 | if (isset($_POST['username']) && isset($_POST['password'])) { |
---|
13 | $user_results = User::get(array("name" => $_POST['username'])); |
---|
14 | if (count($user_results) == 0 || !$user_results) { |
---|
15 | if (strlen($_POST['password']) > 6) { |
---|
16 | $user = new User(null, $_POST['username'], $_POST['password']); |
---|
17 | $user->save(); |
---|
18 | $_SESSION['userUid'] = $user->uid; |
---|
19 | } else { |
---|
20 | $errorMessage[] = "Password is too short"; |
---|
21 | } |
---|
22 | } |
---|
23 | else |
---|
24 | $errorMessage[] = "Username already exists, try something else!"; |
---|
25 | } |
---|
26 | else |
---|
27 | $errorMessage[] = "Please fill in a username and password"; |
---|
28 | } |
---|
29 | |
---|
30 | if (isset($_POST['login'])) { // User clicked the login button |
---|
31 | $user_results = User::get(array("name" => $_POST['username'])); |
---|
32 | if (isset($user_results[0])) { |
---|
33 | if ($user_results[0]->password == $_POST['password']) { |
---|
34 | |
---|
35 | $_SESSION['userUid'] = $user_results[0]->uid; |
---|
36 | var_dump($user_results[0]); |
---|
37 | } else { |
---|
38 | $errorMessage[] = "Incorrect password!"; |
---|
39 | } |
---|
40 | } else { |
---|
41 | $errorMessage[] = "Username doesn't exist!"; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | if (isset($_SESSION['userUid'])) { // User just registered a new account |
---|
46 | redirect('mainmenu.php'); |
---|
47 | } |
---|
48 | ?> |
---|
49 | |
---|
50 | <!DOCTYPE html> |
---|
51 | <html> |
---|
52 | <head> |
---|
53 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
---|
54 | <title>Facilitator</title> |
---|
55 | <?php new StyleSheet("visualeditors"); ?> |
---|
56 | <script type="text/javascript" src="js/menu.js"></script> |
---|
57 | <script type="text/javascript"> |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | </script> |
---|
62 | </head> |
---|
63 | <body> |
---|
64 | <div id="header"> |
---|
65 | <?php new Logo(); ?> |
---|
66 | </div> |
---|
67 | |
---|
68 | <div id="wrapper"> |
---|
69 | |
---|
70 | <div id="content"> |
---|
71 | <div class="largeFrame"> |
---|
72 | <div class="largeTitle">Log in</div> |
---|
73 | <div class="content"> |
---|
74 | <form action="index.php" method="POST"> |
---|
75 | <h3>Username</h3> |
---|
76 | <input type="text" name="username"><br /> |
---|
77 | <h3>Password</h3> |
---|
78 | <input type="password" name="password"><br/><br /> |
---|
79 | <div id="errorDisplay"> |
---|
80 | <?php |
---|
81 | foreach ($errorMessage as $message) { |
---|
82 | echo "<h3 style='color: #FF0000;'>$message</h3>"; |
---|
83 | } |
---|
84 | ?> |
---|
85 | </div> |
---|
86 | <br/> |
---|
87 | <input type="submit" name="login" class="bigButton vertical" value="Log in"> |
---|
88 | </form> |
---|
89 | <form action="register.php" method="POST"> |
---|
90 | <input type="submit" name="register" class="bigButton vertical" value="Register" style="margin-bottom: 0.25em;"> |
---|
91 | </form> |
---|
92 | </div> |
---|
93 | |
---|
94 | </div> |
---|
95 | </div> |
---|
96 | </div> |
---|
97 | </body> |
---|
98 | </html> |
---|