Changeset 151 for Dev/trunk/index.php
- Timestamp:
- 11/08/11 17:02:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/index.php
r142 r151 2 2 require 'classes/master.php'; //should be at top of every page 3 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 4 16 if (isset($_POST['register'])) { 5 17 if ($_POST['username'] != null && $_POST['password'] != null) { 6 $userDBI = new UserDatabaseInterface(); 7 $user_exists = $userDBI->checkUserName($_POST['username']); 18 $dbi = new DatabaseInterface(); 19 $user_results = $dbi->get("user", array("name" => $_POST['username'])); 20 $user_exists = (count($user_results) > 0); 8 21 if (!$user_exists) { 9 $userDBI->addNewUser($_POST); 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 } 10 30 } 11 31 else 12 echo "Username already exists, try something else"; 32 $errorMessage[] = "Username already exists, try something else!"; 33 //echo "Username already exists, try something else"; 13 34 } 14 35 else 15 echo "please fill in a username and password"; 36 $errorMessage[] = "Please fill in a username and password"; 37 //echo "please fill in a username and password"; 16 38 } 17 39 18 if (isset($_SESSION['username'])) 19 redirect('mainmenu.php'); 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 } 20 60 ?> 21 61 … … 27 67 <?php new StyleSheet("awesome"); ?> 28 68 <script type="text/javascript" src="js/menu.js"></script> 69 <script type="text/javascript"> 70 71 72 73 </script> 29 74 </head> 30 75 <body> 31 76 <div id="header"> 32 <?php new Logo(); ?>77 <?php new Logo(); ?> 33 78 </div> 34 79 … … 37 82 <div id="content"> 38 83 <div class="menu"> 39 <form action=" mainmenu.php" method="POST">84 <form action="index.php" method="POST"> 40 85 <h3>Username</h3> 41 86 <input type="text" name="username"><br /> 42 87 <h3>Password</h3> 43 <input type="password" name="password"><br/><br/><br/> 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/> 44 97 <input type="submit" name="login" class="surveyButton bigSurveyButton" value="Log in"> 45 98 </form>
Note: See TracChangeset
for help on using the changeset viewer.