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