procLogin(); } else if(isset($_POST['subjoin'])){ $this->procRegister(); } else if(isset($_POST['subforgot'])){ $this->procForgotPass(); } else if(isset($_POST['subedit'])){ $this->procEditAccount(); } /** * The only other reason user should be directed here * is if he wants to logout, which means user is * logged in currently. */ else if($session->logged_in){ $this->procLogout(); } /** * Should not get here, which means user is viewing this page * by mistake and therefore is redirected. */ else{ if($session->isAdmin()){ header("Location: index.php ");//.$session->referrer); } else { header("Location: index.php"); } } } /** * procLogin - Processes the user submitted login form, if errors * are found, the user is redirected to correct the information, * if not, the user is effectively logged in to the system. */ function procLogin(){ global $session, $form; $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember'])); if($retval){ if($session->isAdmin()){ header("Location: index.php ");//.$session->referrer); } else { header("Location: index.php"); } } else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } /** * procLogout - Simply attempts to log the user out of the system * given that there is no logout form to process. */ function procLogout(){ global $session; $retval = $session->logout(); header("Location: index.php"); } /** * procRegister - Processes the user submitted registration form, * if errors are found, the user is redirected to correct the * information, if not, the user is effectively registered with * the system and an email is (optionally) sent to the newly * created user. */ function procRegister(){ global $session, $form; if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } // Added $_POST['realName'] on Jan 9, 2009 by Jonathan Sundquist $retval = $session->register($_POST['user'], $_POST['realName'], $_POST['pass'], $_POST['email']); if($retval == 0){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = true; header("Location: ".$session->referrer); } else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } else if($retval == 2){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = false; header("Location: ".$session->referrer); } } /** * procForgotPass - Validates the given username then if * everything is fine, a new password is generated and * emailed to the address the user gave on sign up. */ function procForgotPass(){ global $database, $session, $mailer, $form; $subuser = $_POST['user']; $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered
"); } else{ $subuser = stripslashes($subuser); if(strlen($subuser) < 5 || strlen($subuser) > 30 || !eregi("^([0-9a-z])+$", $subuser) || (!$database->usernameTaken($subuser))){ $form->setError($field, "* Username does not exist
"); } } if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); } else{ $newpass = $session->generateRandStr(8); $usrinf = $database->getUserInfo($subuser); $email = $usrinf['email']; if($mailer->sendNewPass($subuser,$email,$newpass)){ $database->updateUserField($subuser, "password", md5($newpass)); $_SESSION['forgotpass'] = true; } else{ $_SESSION['forgotpass'] = false; } } header("Location: ".$session->referrer); } /** * procEditAccount - Attempts to edit the user's account * information, including the password, which must be verified * before a change is made. */ function procEditAccount(){ global $session, $form; $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']); if($retval){ $_SESSION['useredit'] = true; header("Location: ".$session->referrer); } else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } }; $process = new Process; ?>