Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 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("php/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.html");
  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.html");
  83. }
  84.  
  85. /**
  86. * procRegister - Processes the user submitted registration form,
  87. * if errors are found, the user is redirected to correct the
  88. * information, if not, the user is effectively registered with
  89. * the system and an email is (optionally) sent to the newly
  90. * created user.
  91. */
  92. function procRegister(){
  93. global $session, $form;
  94. /* Convert username to all lowercase (by option) */
  95. if(ALL_LOWERCASE){
  96. $_POST['user'] = strtolower($_POST['user']);
  97. }
  98. /* Registration attempt */
  99. $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email']);
  100.  
  101. /* Registration Successful */
  102. if($retval == 0){
  103. $_SESSION['reguname'] = $_POST['user'];
  104. $_SESSION['regsuccess'] = true;
  105. header("Location: ".$session->referrer);
  106. }
  107. /* Error found with form */
  108. else if($retval == 1){
  109. $_SESSION['value_array'] = $_POST;
  110. $_SESSION['error_array'] = $form->getErrorArray();
  111. header("Location: ".$session->referrer);
  112. }
  113. /* Registration attempt failed */
  114. else if($retval == 2){
  115. $_SESSION['reguname'] = $_POST['user'];
  116. $_SESSION['regsuccess'] = false;
  117. header("Location: ".$session->referrer);
  118. }
  119. }
  120.  
  121. /**
  122. * procForgotPass - Validates the given username then if
  123. * everything is fine, a new password is generated and
  124. * emailed to the address the user gave on sign up.
  125. */
  126. function procForgotPass(){
  127. global $database, $session, $mailer, $form;
  128. /* Username error checking */
  129. $subuser = $_POST['user'];
  130. $field = "user"; //Use field name for username
  131. if(!$subuser || strlen($subuser = trim($subuser)) == 0){
  132. $form->setError($field, "* Username not entered<br>");
  133. }
  134. else{
  135. /* Make sure username is in database */
  136. $subuser = stripslashes($subuser);
  137. if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
  138. !eregi("^([0-9a-z])+$", $subuser) ||
  139. (!$database->usernameTaken($subuser))){
  140. $form->setError($field, "* Username does not exist<br>");
  141. }
  142. }
  143.  
  144. /* Errors exist, have user correct them */
  145. if($form->num_errors > 0){
  146. $_SESSION['value_array'] = $_POST;
  147. $_SESSION['error_array'] = $form->getErrorArray();
  148. }
  149. /* Generate new password and email it to user */
  150. else{
  151. /* Generate new password */
  152. $newpass = $session->generateRandStr(8);
  153.  
  154. /* Get email of user */
  155. $usrinf = $database->getUserInfo($subuser);
  156. $email = $usrinf['email'];
  157.  
  158. /* Attempt to send the email with new password */
  159. if($mailer->sendNewPass($subuser,$email,$newpass)){
  160. /* Email sent, update database */
  161. $database->updateUserField($subuser, "password", md5($newpass));
  162. $_SESSION['forgotpass'] = true;
  163. }
  164. /* Email failure, do not change password */
  165. else{
  166. $_SESSION['forgotpass'] = false;
  167. }
  168. }
  169.  
  170. header("Location: ".$session->referrer);
  171. }
  172.  
  173. /**
  174. * procEditAccount - Attempts to edit the user's account
  175. * information, including the password, which must be verified
  176. * before a change is made.
  177. */
  178. function procEditAccount(){
  179. global $session, $form;
  180. /* Account edit attempt */
  181. $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);
  182.  
  183. /* Account edit successful */
  184. if($retval){
  185. $_SESSION['useredit'] = true;
  186. header("Location: ".$session->referrer);
  187. }
  188. /* Error found with form */
  189. else{
  190. $_SESSION['value_array'] = $_POST;
  191. $_SESSION['error_array'] = $form->getErrorArray();
  192. header("Location: ".$session->referrer);
  193. }
  194. }
  195. };
  196.  
  197. /* Initialize process */
  198. $process = new Process;
  199.  
  200. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement