procLogin(); } /* User submitted registration form */ else if(isset($_POST['subjoin'])){ $this->procRegister(); } /* User submitted forgot password form */ else if(isset($_POST['subforgot'])){ $this->procForgotPass(); } /* User submitted forgot password form */ else if(isset($_POST['subforgotuser'])){ $this->procForgotUser(); } /* User submitted edit account form */ 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{ header("Location: signin/"); } } /** * 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; /* Login attempt */ $retval = $session->login($_POST['username'], $_POST['password1'], isset($_POST['remember'])); /* Login successful */ if($retval){ //echo $_SESSION['username']; $rpage = $_POST['repage']; if($rpage=='chk'){$page = 'checkout.php';}else{$page = 'customer/dashboard/';} header("Location: ".MAIN_URL.$page); } /* Login failed */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: signin/"); } } /** * 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: signin/"); } /** * 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; /* Convert username to all lowercase (by option) */ if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } /* Registration attempt */ $username=$_POST['username']; $password=$_POST['password1']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $email=$_POST['email']; $phone=$_POST['phone']; $address=$_POST['address']; $city=$_POST['city']; $country=$_POST['country']; $retval = $session->register($username, $password, $firstname, $lastname, $email, $country, $phone, $address, $city); /* Registration Successful */ if($retval == 0){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = true; //header("Location: ".$session->referrer); header("Location: signup/"); } /* Error found with form */ else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); //header("Location: ".$session->referrer); header("Location: signup/"); } /* Registration attempt failed */ else if($retval == 2){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = false; //header("Location: ".$session->referrer); header("Location: signup/"); } } /** * 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; /* Username error checking */ $subuser = $_POST['user']; $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered
"); } else{ /* Make sure username is in database */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5 || strlen($subuser) > 30 || !preg_match('/^[0-9a-z&#_ ]+$/i', $subuser) || (!$database->usernameTaken($subuser))){ $form->setError($field, "* Username does not exist
"); } } /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); } /* Generate new password and email it to user */ else{ /* Generate new password */ //$newpass = $session->generateRandStr(8); /* Get email of user */ $usrinf = $database->getUserInfo($subuser); $email = $usrinf['email']; $newpass = $usrinf['password']; /* Attempt to send the email with new password */ if($mailer->sendNewPass($subuser,$email,$newpass)){ /* Email sent, update database */ //$database->updateUserField($subuser, "password", $newpass); $_SESSION['forgotpass'] = true; } /* Email failure, do not change password */ else{ $_SESSION['forgotpass'] = false; } } header("Location: ".$session->referrer); } /** * procForgotUsername - Validates the given email then if * everything is fine, send username is generated and * emailed to the address the user gave on sign up. */ function procForgotUser(){ global $database, $session, $mailer, $form; /* Username error checking */ $subemail = $_POST['email']; $field = "email"; //Use field name for username if(!$subemail || strlen($subemail = trim($subemail)) == 0){ $form->setError($field, "* Email not entered
"); } else{ /* Make sure email is in database */ $subemail = stripslashes($subemail); if(strlen($subemail) < 5 || strlen($subemail) > 30 || !preg_match('/^[a-z\d_\.\-]+@([a-z\d\-]+)(?:\.(?1)){1,2}$/i',$subemail) || !$database->confirmEmail($subemail)){ $form->setError($field, "* Email does not exist
"); } } /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); } /* Generate new password and email it to user */ else{ /* Generate new password */ //$newpass = $session->generateRandStr(8); /* Get username by email */ $username = $database->getUserbyEmail($subemail); /* Get email of user */ $usrinf = $database->getUserInfo($username); //$email = $usrinf['email']; $newpass = $usrinf['password']; /* Attempt to send the email with new password */ if($mailer->sendUser($username,$subemail,$newpass)){ /* Email sent, update database */ //$database->updateUserField($subuser, "password", $newpass); $_SESSION['forgotuser'] = true; } /* Email failure, do not change password */ else{ $_SESSION['forgotuser'] = 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; /* Account edit attempt */ $birth_date=$_POST['birth_year'].'-'.$_POST['birth_month'].'-'.$_POST['birth_day']; $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'], $_POST['Old_profile_picture'], $_FILES['profile_picture'], $_POST['about_user'], $_POST['full_name'],$_POST['gender'],$birth_date,$_POST['City'],$_POST['Country']); /* Account edit successful */ if($retval){ $_SESSION['useredit'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: userhome.php"); } } } /* Initialize process */ $process = new Process; echo 'dfgdfg'; ?>