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