Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. <?
  2. /**
  3. * Process.php
  4. *
  5. * The Process class is meant to simplify the task of processing
  6. * user submitted forms, redirecting the user to the correct
  7. * pages if errors are found, or if form is successful, either
  8. * way. Also handles the logout procedure.
  9. *
  10. * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
  11. * Last Updated: August 19, 2004
  12. */
  13. include("include/session.php");
  14.  
  15. class Process
  16. {
  17. /* Class constructor */
  18. function Process(){
  19. global $session;
  20. /* User submitted login form */
  21. if(isset($_POST['sublogin'])){
  22. $this->procLogin();
  23. }
  24. /* User submitted registration form */
  25. else if(isset($_POST['subjoin'])){
  26. $this->procRegister();
  27. }
  28. /* User submitted forgot password form */
  29. else if(isset($_POST['subforgot'])){
  30. $this->procForgotPass();
  31. }
  32. /* User submitted edit account form */
  33. else if(isset($_POST['subedit'])){
  34. $this->procEditAccount();
  35. }
  36. /**
  37. * The only other reason user should be directed here
  38. * is if he wants to logout, which means user is
  39. * logged in currently.
  40. */
  41. else if($session->logged_in){
  42. $this->procLogout();
  43. }
  44. /**
  45. * Should not get here, which means user is viewing this page
  46. * by mistake and therefore is redirected.
  47. */
  48. else{
  49. header("Location: index.php");
  50. }
  51. }
  52.  
  53. /**
  54. * procLogin - Processes the user submitted login form, if errors
  55. * are found, the user is redirected to correct the information,
  56. * if not, the user is effectively logged in to the system.
  57. */
  58. function procLogin(){
  59. global $session, $form;
  60. /* Login attempt */
  61. $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
  62.  
  63. /* Login successful */
  64. if($retval){
  65. header("Location: ".$session->referrer);
  66. }
  67. /* Login failed */
  68. else{
  69. $_SESSION['value_array'] = $_POST;
  70. $_SESSION['error_array'] = $form->getErrorArray();
  71. header("Location: ".$session->referrer);
  72. }
  73. }
  74.  
  75. /**
  76. * procLogout - Simply attempts to log the user out of the system
  77. * given that there is no logout form to process.
  78. */
  79. function procLogout(){
  80. global $session;
  81. $retval = $session->logout();
  82. header("Location: index.php");
  83. }
  84.  
  85. function sanitize($data)
  86. {
  87. // remove whitespaces (not a must though)
  88. $data = trim($data);
  89.  
  90. // apply stripslashes if magic_quotes_gpc is enabled
  91. if(get_magic_quotes_gpc())
  92. {
  93. $data = stripslashes($data);
  94. }
  95.  
  96. // a mySQL connection is required before using this function
  97. $data = mysql_real_escape_string($data);
  98.  
  99. return $data;
  100. }
  101.  
  102. /**
  103. * procRegister - Processes the user submitted registration form,
  104. * if errors are found, the user is redirected to correct the
  105. * information, if not, the user is effectively registered with
  106. * the system and an email is (optionally) sent to the newly
  107. * created user.
  108. */
  109. function procRegister(){
  110. global $session, $form;
  111. /* Convert username to all lowercase (by option) */
  112. if(ALL_LOWERCASE){
  113. $_POST['user'] = strtolower($_POST['user']);
  114. }
  115.  
  116.  
  117. $uname = sanitize($_post['user']);
  118. $upass = sanitize($_post['pass']);
  119. $uemail = sanitize($_post['email']);
  120.  
  121.  
  122.  
  123. /* Registration attempt */
  124. $retval = $session->register($uname, $upass, $uemail);
  125.  
  126. /* Registration Successful */
  127. if($retval == 0){
  128. $_SESSION['reguname'] = $_POST['user'];
  129. $_SESSION['regsuccess'] = true;
  130. header("Location: ".$session->referrer);
  131. }
  132. /* Error found with form */
  133. else if($retval == 1){
  134. $_SESSION['value_array'] = $_POST;
  135. $_SESSION['error_array'] = $form->getErrorArray();
  136. header("Location: ".$session->referrer);
  137. }
  138. /* Registration attempt failed */
  139. else if($retval == 2){
  140. $_SESSION['reguname'] = $_POST['user'];
  141. $_SESSION['regsuccess'] = false;
  142. header("Location: ".$session->referrer);
  143. }
  144. }
  145.  
  146. /**
  147. * procForgotPass - Validates the given username then if
  148. * everything is fine, a new password is generated and
  149. * emailed to the address the user gave on sign up.
  150. */
  151. function procForgotPass(){
  152. global $database, $session, $mailer, $form;
  153. /* Username error checking */
  154. $subuser = $_POST['user'];
  155. $field = "user"; //Use field name for username
  156. if(!$subuser || strlen($subuser = trim($subuser)) == 0){
  157. $form->setError($field, "* Username not entered<br>");
  158. }
  159. else{
  160. /* Make sure username is in database */
  161. $subuser = stripslashes($subuser);
  162. if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
  163. !eregi("^([0-9a-z])+$", $subuser) ||
  164. (!$database->usernameTaken($subuser))){
  165. $form->setError($field, "* Username does not exist<br>");
  166. }
  167. }
  168.  
  169. /* Errors exist, have user correct them */
  170. if($form->num_errors > 0){
  171. $_SESSION['value_array'] = $_POST;
  172. $_SESSION['error_array'] = $form->getErrorArray();
  173. }
  174. /* Generate new password and email it to user */
  175. else{
  176. /* Generate new password */
  177. $newpass = $session->generateRandStr(8);
  178.  
  179. /* Get email of user */
  180. $usrinf = $database->getUserInfo($subuser);
  181. $email = $usrinf['email'];
  182.  
  183. /* Attempt to send the email with new password */
  184. if($mailer->sendNewPass($subuser,$email,$newpass)){
  185. /* Email sent, update database */
  186. $database->updateUserField($subuser, "password", md5($newpass));
  187. $_SESSION['forgotpass'] = true;
  188. }
  189. /* Email failure, do not change password */
  190. else{
  191. $_SESSION['forgotpass'] = false;
  192. }
  193. }
  194.  
  195. header("Location: ".$session->referrer);
  196. }
  197.  
  198. /**
  199. * procEditAccount - Attempts to edit the user's account
  200. * information, including the password, which must be verified
  201. * before a change is made.
  202. */
  203. function procEditAccount(){
  204. global $session, $form;
  205. /* Account edit attempt */
  206. $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);
  207.  
  208. /* Account edit successful */
  209. if($retval){
  210. $_SESSION['useredit'] = true;
  211. header("Location: ".$session->referrer);
  212. }
  213. /* Error found with form */
  214. else{
  215. $_SESSION['value_array'] = $_POST;
  216. $_SESSION['error_array'] = $form->getErrorArray();
  217. header("Location: ".$session->referrer);
  218. }
  219. }
  220. };
  221.  
  222. /* Initialize process */
  223. $process = new Process;
  224.  
  225. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement