Advertisement
Guest User

Untitled

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