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 | //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 | |
---|
16 | if (isset($_POST['register'])) { |
---|
17 | if ($_POST['username'] != null && $_POST['password'] != null) { |
---|
18 | $dbi = new DatabaseInterface(); |
---|
19 | $user_results = $dbi->get("user", array("name" => $_POST['username'])); |
---|
20 | $user_exists = (count($user_results) > 0); |
---|
21 | if (!$user_exists) { |
---|
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 | } |
---|
30 | } |
---|
31 | else |
---|
32 | $errorMessage[] = "Username already exists, try something else!"; |
---|
33 | //echo "Username already exists, try something else"; |
---|
34 | } |
---|
35 | else |
---|
36 | $errorMessage[] = "Please fill in a username and password"; |
---|
37 | //echo "please fill in a username and password"; |
---|
38 | } |
---|
39 | |
---|
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 | } |
---|
60 | ?> |
---|
61 | |
---|
62 | <!DOCTYPE html> |
---|
63 | <html> |
---|
64 | <head> |
---|
65 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
---|
66 | <title>Facilitator</title> |
---|
67 | <?php new StyleSheet("awesome"); ?> |
---|
68 | <script type="text/javascript" src="js/menu.js"></script> |
---|
69 | <script type="text/javascript"> |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | </script> |
---|
74 | </head> |
---|
75 | <body> |
---|
76 | <div id="header"> |
---|
77 | <?php new Logo(); ?> |
---|
78 | </div> |
---|
79 | |
---|
80 | <div id="wrapper"> |
---|
81 | |
---|
82 | <div id="content"> |
---|
83 | <div class="menu"> |
---|
84 | <form action="index.php" method="POST"> |
---|
85 | <h3>Username</h3> |
---|
86 | <input type="text" name="username"><br /> |
---|
87 | <h3>Password</h3> |
---|
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/> |
---|
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> |
---|
102 | </div> |
---|
103 | </div> |
---|
104 | </div> |
---|
105 | </body> |
---|
106 | </html> |
---|