PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/p7/Old/home.php

https://github.com/codyaustun/PASS
PHP | 305 lines | 249 code | 39 blank | 17 comment | 16 complexity | 23d2383d79da7b6689e38f710462ce0b MD5 | raw file
  1. <?php // Home page to process login, signup, show html
  2. require_once 'info.php'; //database access information
  3. // function to process user input
  4. function sanitizeString($var){
  5. $var = stripslashes($var); //gets ride of unwanted slashes
  6. $var = htmlentities($var); //removes HTML from a string
  7. $var = strip_tags($var); //strip HTML entirely from an input
  8. return $var;
  9. }
  10. $salt=$useremail=$password=""; //initialize username and password for safety
  11. $db_server=mysql_connect($db_hostname,$db_username,$db_password);
  12. if(!$db_server) die("Unable to Connect to MySQL: ". mysql_error());
  13. mysql_select_db($db_database) or die("Unable to select database: " .mysql_error());
  14. if (isset($_POST['email']) && !(isset($_POST['firstName']) && (isset($_POST['lastName']))))
  15. {
  16. $useremail = sanitizeString($_POST['email']);
  17. $password = sanitizeString($_POST['password']);
  18. $salt = "At MIT 6.470 is one of the best IAP classes to take.";
  19. $hash = sha1($password.$salt); // hash password for security
  20. if ($useremail == "" || $password == "")
  21. {
  22. echo "All fields have not been entered";
  23. // to be updated so that javascripts is inserted here
  24. // to show pop up box
  25. }
  26. else
  27. {
  28. $query = "SELECT id,first_name FROM auth_user WHERE
  29. email = '$useremail' AND password = '$hash'";
  30. $result = mysql_query($query);
  31. if (!$result) die("Database access failed: " . mysql_error());
  32. elseif (mysql_num_rows($result))
  33. {
  34. $row = mysql_fetch_row($result);
  35. session_start();
  36. $_SESSION['user_id'] = $row[0];
  37. $_SESSION['first_name'] = $row[1];
  38. $date = date("Y-m-d",time());
  39. $query = "UPDATE `kwadwo+IAP`.`auth_user` SET `last_login`='$date' WHERE `auth_user`.`id`='$row[0]'";
  40. mysql_query($query);
  41. echo "You have logged in!";
  42. header("Location: dashboard.php");
  43. }
  44. else
  45. {
  46. //echo "$useremail $hash ";
  47. die("Invalid username/password combination");
  48. // to be updated so taht javascripts is inserted here
  49. // to show pop up box
  50. }
  51. }
  52. }
  53. // if signing up...process form as sign
  54. elseif (isset($_POST['firstName']))
  55. {
  56. $firstName = sanitizeString($_POST['firstName']);
  57. $lastName = sanitizeString($_POST['lastName']);
  58. $useremail = sanitizeString($_POST['email_su']);
  59. $password = sanitizeString($_POST['password_su']);
  60. $confirm = sanitizeString($_POST['confirm']);
  61. $salt = "At MIT 6.470 is one of the best IAP classes to take.";
  62. $hash = sha1($password.$salt); //hash password for security
  63. $date = date("Y-m-d",time());
  64. if($useremail == "" || $password == "")
  65. {
  66. echo "missing password or username";
  67. // javascript to be inserted here
  68. }
  69. elseif($password!=$confirm)
  70. {
  71. echo "password and confirmation do not match up!";
  72. // javascript to be inserted here!
  73. }
  74. else
  75. {
  76. $query = "INSERT INTO `kwadwo+IAP`.`users` (`id`, `first_name`, `last_name`, `email`, `password`, `status`, `last_login`, `created_on`) VALUES (NULL, '$firstName', '$lastName', '$useremail', '$hash', 'F', NULL, '$date')";
  77. mysql_query($query);
  78. echo "you have successfully signed up!";
  79. // some javascript code should go here as well
  80. }
  81. }
  82. else // show regular HTML page as normal
  83. {
  84. /*
  85. ****************************************************************
  86. ******************HTML HOME PAGE for PASS *************************
  87. ******************************************************************
  88. */
  89. echo <<<_HTML
  90. <html>
  91. <head>
  92. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  93. <title>PASS - Job Hunting Made Simple</title>
  94. <link href="images/favicon.ico" rel="shortcut icon" />
  95. <link href="images/favicon.ico" rel="icon" type="image/x-icon" />
  96. <link rel="stylesheet" href="jquery-ui-1.8.7.custom/css/ui-lightness/jquery-ui-1.8.7.custom.css" />
  97. <link rel="stylesheet" href="styles/baseThick.css" />
  98. <link rel="stylesheet" href="styles/signup.css" />
  99. <script type="text/javascript" src="scripts/jquery-1.4.4.min.js"></script>
  100. <script type="text/javascript" src="jquery-ui-1.8.7.custom/js/jquery-ui-1.8.7.custom.min.js"></script>
  101. <script type="text/javascript" src="scripts/feedback.js"></script>
  102. <script type="text/javascript" src="scripts/growl.js"></script>
  103. <script type="text/javascript" src="scripts/signup.js"></script>
  104. </head>
  105. <body>
  106. <div id="topOuter">
  107. <!-- topInner Start -->
  108. <div id="topInner">
  109. <!-- Header Start -->
  110. <div id="header">
  111. <div id="login">
  112. <form id="loginForm" method="post" action="home.php" >
  113. <table>
  114. <tr>
  115. <td>
  116. <label for="email">Email:</label>
  117. </td>
  118. <td>
  119. <input type="email" name="email" value='$useremail' id="email"/>
  120. </td>
  121. </tr>
  122. <tr>
  123. <td>
  124. <label for="password">Password:</label>
  125. </td>
  126. <td>
  127. <input type="password" name="password" value="" id="password"/>
  128. </td>
  129. </tr>
  130. <tr>
  131. <td colspan="2">
  132. <input type="submit" name="login" value="Login" id="loginBut"/>
  133. </td>
  134. </tr>
  135. </table>
  136. </form>
  137. </div>
  138. </div>
  139. <!-- Header End -->
  140. <!-- Navigation Start -->
  141. <div id="nav">
  142. <div id="welcome">
  143. <div id="hi">
  144. </div>
  145. <div id="firstNameC">
  146. </div>
  147. <div id="lastNameC">
  148. </div>
  149. <div id="yay">
  150. </div>
  151. </div>
  152. </div>
  153. <!-- Navigation End -->
  154. </div>
  155. <!-- topInner End -->
  156. </div>
  157. <div id="bottomOuter">
  158. <!-- bottomInner Start -->
  159. <div id="bottomInner">
  160. <!-- Content Start -->
  161. <div id="content">
  162. <!-- col1 Start -->
  163. <div id="col1">
  164. <div id="vidDes">
  165. </div>
  166. <div id="des">
  167. <p class= "description">
  168. Welcome to <strong>Pass</strong>,
  169. the Professional Automatic Searching System. Pass was created
  170. with the aim of creating an all in one job searching system that would allow users to not
  171. only find jobs that fit their needs easier, but also allow them to create a more
  172. efficient way to access their information all in one place.
  173. </p>
  174. </div>
  175. </div>
  176. <!-- col1 start -->
  177. <!-- col2 Start -->
  178. <div id="col2">
  179. <form id="signUp" method="post" action="home.php">
  180. <h2>Sign up</h2>
  181. <h3>It's free, and always will be.</h3>
  182. <br />
  183. <table>
  184. <tr>
  185. <td class="fieldLabel">
  186. <label for="firstName">First Name:</label>
  187. </td>
  188. <td>
  189. <input name="firstName" id="firstName" value='$firstName'
  190. type="text" class="clear fieldBox"/>
  191. </td>
  192. </tr>
  193. <tr>
  194. <td class="fieldLabel">
  195. <label for="lastName">Last Name:</label>
  196. </td>
  197. <td>
  198. <input name="lastName" id="lastName" value='$lastName'
  199. type="text" class="clear fieldBox"/>
  200. </td>
  201. </tr>
  202. <tr>
  203. <td class="fieldLabel">
  204. <label for="email_su">Email:</label>
  205. </td>
  206. <td>
  207. <input name="email_su" value='$useremail' id="email_su" value='$useremail' type="text" class="clear fieldBox" />
  208. </td>
  209. </tr>
  210. <tr>
  211. <td class="fieldLabel">
  212. <label for="password_su">Password:</label>
  213. </td>
  214. <td>
  215. <input name="password_su" id="password_su" class="fieldBox" type="password" />
  216. </td>
  217. </tr>
  218. <tr>
  219. <td class="fieldLabel">
  220. <label for="confirm">Confirm Password:</label>
  221. </td>
  222. <td>
  223. <input name="confirm" id="confirm" class="fieldBox" type="password"/>
  224. </td>
  225. </tr>
  226. <tr>
  227. <td>
  228. </td>
  229. <td>
  230. <input type="submit" name="submit" id="signUpSubmit" value="Join!" />
  231. </td>
  232. </tr>
  233. </table>
  234. </form>
  235. </div>
  236. <!-- col2 End -->
  237. </div>
  238. <!-- Content End -->
  239. </div>
  240. <div id="footer">
  241. Footer!
  242. </div>
  243. </div>
  244. </body>
  245. </html>
  246. _HTML;
  247. }
  248. ?>