Advertisement
Guest User

process.php

a guest
Mar 25th, 2015
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. <?
  2.  
  3. /**
  4.  
  5. * Process.php
  6.  
  7. *
  8.  
  9. * The Process class is meant to simplify the task of processing
  10.  
  11. * user submitted forms, redirecting the user to the correct
  12.  
  13. * pages if errors are found, or if form is successful, either
  14.  
  15. * way. Also handles the logout procedure.
  16.  
  17. *
  18.  
  19. * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
  20.  
  21. * Last Updated: August 19, 2004
  22.  
  23. */
  24.  
  25. include("include/session.php");
  26.  
  27.  
  28.  
  29. class Process
  30.  
  31. {
  32.  
  33. /* Class constructor */
  34.  
  35. function Process(){
  36.  
  37. global $session;
  38.  
  39. /* User submitted login form */
  40.  
  41. if(isset($_POST['sublogin'])){
  42.  
  43. $this->procLogin();
  44.  
  45. }
  46.  
  47. /* User submitted registration form */
  48.  
  49. else if(isset($_POST['subjoin'])){
  50.  
  51. $this->procRegister();
  52.  
  53. }
  54.  
  55. /* User submitted forgot password form */
  56.  
  57. else if(isset($_POST['subforgot'])){
  58.  
  59. $this->procForgotPass();
  60.  
  61. }
  62.  
  63. /* User submitted edit account form */
  64.  
  65. else if(isset($_POST['subedit'])){
  66.  
  67. $this->procEditAccount();
  68.  
  69. }
  70.  
  71.  
  72.  
  73. /**
  74.  
  75. * The only other reason user should be directed here
  76.  
  77. * is if he wants to logout, which means user is
  78.  
  79. * logged in currently.
  80.  
  81. */
  82.  
  83. else if($session->logged_in){
  84.  
  85. $this->procLogout();
  86.  
  87. }
  88.  
  89. /**
  90.  
  91. * Should not get here, which means user is viewing this page
  92.  
  93. * by mistake and therefore is redirected.
  94.  
  95. */
  96.  
  97. else{
  98.  
  99. header("Location: index.php");
  100.  
  101. }
  102.  
  103. }
  104.  
  105.  
  106.  
  107. /**
  108.  
  109. * procLogin - Processes the user submitted login form, if errors
  110.  
  111. * are found, the user is redirected to correct the information,
  112.  
  113. * if not, the user is effectively logged in to the system.
  114.  
  115. */
  116.  
  117. function procLogin(){
  118.  
  119. global $session, $form;
  120.  
  121. /* Login attempt */
  122.  
  123. $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
  124.  
  125.  
  126.  
  127. /* Login successful */
  128.  
  129. if($retval){
  130.  
  131. header("Location: news.php");
  132.  
  133. }
  134.  
  135. /* Login failed */
  136.  
  137. else{
  138.  
  139. $_SESSION['value_array'] = $_POST;
  140.  
  141. $_SESSION['error_array'] = $form->getErrorArray();
  142.  
  143. header("Location: ".$session->referrer);
  144.  
  145. }
  146.  
  147. }
  148.  
  149.  
  150.  
  151. /**
  152.  
  153. * procLogout - Simply attempts to log the user out of the system
  154.  
  155. * given that there is no logout form to process.
  156.  
  157. */
  158.  
  159. function procLogout(){
  160.  
  161. global $session;
  162.  
  163. $retval = $session->logout();
  164.  
  165. header("Location: index.php");
  166.  
  167. }
  168.  
  169.  
  170.  
  171. /**
  172.  
  173. * procRegister - Processes the user submitted registration form,
  174.  
  175. * if errors are found, the user is redirected to correct the
  176.  
  177. * information, if not, the user is effectively registered with
  178.  
  179. * the system and an email is (optionally) sent to the newly
  180.  
  181. * created user.
  182.  
  183. */
  184.  
  185. function procRegister(){
  186.  
  187. global $session, $form;
  188.  
  189. /* Convert username to all lowercase (by option) */
  190.  
  191. if(ALL_LOWERCASE){
  192.  
  193. $_POST['user'] = strtolower($_POST['user']);
  194.  
  195. }
  196.  
  197. /* Registration attempt */
  198.  
  199. $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['description'], $_POST['game'], $_POST['name'], $_POST['age'], $_POST['quote']);
  200.  
  201.  
  202.  
  203. /* Registration Successful */
  204.  
  205. if($retval == 0){
  206.  
  207. $_SESSION['reguname'] = $_POST['user'];
  208.  
  209. $_SESSION['regsuccess'] = true;
  210.  
  211. header("Location: ".$session->referrer);
  212.  
  213. }
  214.  
  215. /* Error found with form */
  216.  
  217. else if($retval == 1){
  218.  
  219. $_SESSION['value_array'] = $_POST;
  220.  
  221. $_SESSION['error_array'] = $form->getErrorArray();
  222.  
  223. header("Location: ".$session->referrer);
  224.  
  225. }
  226.  
  227. /* Registration attempt failed */
  228.  
  229. else if($retval == 2){
  230.  
  231. $_SESSION['reguname'] = $_POST['user'];
  232.  
  233. $_SESSION['regsuccess'] = false;
  234.  
  235. header("Location:".$session->referrer);
  236.  
  237. }
  238.  
  239. }
  240.  
  241.  
  242.  
  243. /**
  244.  
  245. * procForgotPass - Validates the given username then if
  246.  
  247. * everything is fine, a new password is generated and
  248.  
  249. * emailed to the address the user gave on sign up.
  250.  
  251. */
  252.  
  253. function procForgotPass(){
  254.  
  255. global $database, $session, $mailer, $form;
  256.  
  257. /* Username error checking */
  258.  
  259. $subuser = $_POST['user'];
  260.  
  261. $field = "user"; //Use field name for username
  262.  
  263. if(!$subuser || strlen($subuser = trim($subuser)) == 0){
  264.  
  265. $form->setError($field, "* Username not entered<br>");
  266.  
  267. }
  268.  
  269. else{
  270.  
  271. /* Make sure username is in database */
  272.  
  273. $subuser = stripslashes($subuser);
  274.  
  275. if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
  276.  
  277. !eregi("^([0-9a-z])+$", $subuser) ||
  278.  
  279. (!$database->usernameTaken($subuser))){
  280.  
  281. $form->setError($field, "* Username does not exist<br>");
  282.  
  283. }
  284.  
  285. }
  286.  
  287.  
  288.  
  289. /* Errors exist, have user correct them */
  290.  
  291. if($form->num_errors > 0){
  292.  
  293. $_SESSION['value_array'] = $_POST;
  294.  
  295. $_SESSION['error_array'] = $form->getErrorArray();
  296.  
  297. }
  298.  
  299. /* Generate new password and email it to user */
  300.  
  301. else{
  302.  
  303. /* Generate new password */
  304.  
  305. $newpass = $session->generateRandStr(8);
  306.  
  307.  
  308.  
  309. /* Get email of user */
  310.  
  311. $usrinf = $database->getUserInfo($subuser);
  312.  
  313. $email = $usrinf['email'];
  314.  
  315.  
  316.  
  317. /* Attempt to send the email with new password */
  318.  
  319. if($mailer->sendNewPass($subuser,$email,$newpass)){
  320.  
  321. /* Email sent, update database */
  322.  
  323. $database->updateUserField($subuser, "password", md5($newpass));
  324.  
  325. $_SESSION['forgotpass'] = true;
  326.  
  327. }
  328.  
  329. /* Email failure, do not change password */
  330.  
  331. else{
  332.  
  333. $_SESSION['forgotpass'] = false;
  334.  
  335. }
  336.  
  337. }
  338.  
  339.  
  340.  
  341. header("Location: ".$session->referrer);
  342.  
  343. }
  344.  
  345.  
  346.  
  347. /**
  348.  
  349. * procEditAccount - Attempts to edit the user's account
  350.  
  351. * information, including the password, which must be verified
  352.  
  353. * before a change is made.
  354.  
  355. */
  356.  
  357. function procEditAccount(){
  358.  
  359. global $session, $form;
  360.  
  361. /* Account edit attempt */
  362.  
  363. $retval = $session->editAccount($_POST['description'], $_POST['game'], $_POST['name'], $_POST['age'], $_POST['quote'], $_POST['curpass'], $_POST['newpass'], $_POST['email']);
  364.  
  365.  
  366.  
  367. /* Account edit successful */
  368.  
  369. if($retval){
  370.  
  371. $_SESSION['useredit'] = true;
  372.  
  373. header("Location: ".$session->referrer);
  374.  
  375. }
  376.  
  377. /* Error found with form */
  378.  
  379. else{
  380.  
  381. $_SESSION['value_array'] = $_POST;
  382.  
  383. $_SESSION['error_array'] = $form->getErrorArray();
  384.  
  385. header("Location: ".$session->referrer);
  386.  
  387. }
  388.  
  389. }
  390.  
  391.  
  392.  
  393. };
  394.  
  395.  
  396.  
  397. /* Initialize process */
  398.  
  399. $process = new Process;
  400.  
  401.  
  402.  
  403. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement