/*======================================================================*\
|| #################################################################### ||
|| # Musicbox Version 2.3 # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright © 2005–2006 MusicboxV2.com All Rights Reserved. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- MUSICBOX IS NOT FREE SOFTWARE ---------------- # ||
|| # Licensed to Paid Customers Only # ||
|| #################################################################### ||
\*======================================================================*/
include("sources/session.php");
class Process
{
/* Class constructor */
function Process(){
global $session;
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
/* User submitted login form */
if(isset($HTTP_POST_VARS['sublogin'])){
$this->procLogin();
}
/* User submitted registration form */
else if(isset($HTTP_POST_VARS['subjoin'])){
$this->procRegister();
}
/* User submitted forgot password form */
else if(isset($HTTP_POST_VARS['subforgot'])){
$this->procForgotPass();
}
/* User submitted edit account form */
else if(isset($HTTP_POST_VARS['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();
header("Location:index.php");
}
/**
* Should not get here, which means user is viewing this page
* by mistake and therefore is redirected.
*/
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;
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
global $value_array,$error_array;
session_start();
/* Login attempt */
$retval = $session->login($HTTP_POST_VARS['user'], $HTTP_POST_VARS['pass'], isset($HTTP_POST_VARS['remember']));
/* Login successful */
if($retval){
header("Location:index.php");
}
/* Login failed */
else{
$HTTP_SESSION_VARS['value_array'] = $HTTP_POST_VARS;
$HTTP_SESSION_VARS['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;
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
$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;
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
global $reguname,$regsuccess;
global $value_array,$error_array;
session_start();
/* Convert username to all lowercase (by option) */
if(ALL_LOWERCASE){
$HTTP_POST_VARS['user'] = strtolower($HTTP_POST_VARS['user']);
}
/* Registration attempt */
$retval = $session->register($HTTP_POST_VARS['user'], $HTTP_POST_VARS['pass'], $HTTP_POST_VARS['pass_confirm'], $HTTP_POST_VARS['email'], $HTTP_POST_VARS['sex'], $HTTP_POST_VARS['country'], $HTTP_POST_VARS['newsletter'], $HTTP_POST_VARS['terms']);
/* Registration Successful */
if($retval == 0){
$reguname = $HTTP_POST_VARS['user'];//$HTTP_SESSION_VARS['reguname'] = $HTTP_POST_VARS['user']; //
$regsuccess = true;// $HTTP_SESSION_VARS['regsuccess'] = true; //
header("Location:".$session->referrer);
}
/* Error found with form */
else if($retval == 1){
$value_array = $HTTP_POST_VARS;//$HTTP_SESSION_VARS['value_array'] = $HTTP_POST_VARS; //
$error_array = $form->getErrorArray();// $HTTP_SESSION_VARS['error_array'] = $form->getErrorArray(); //
header("Location:".$session->referrer);
}
/* Registration attempt failed */
else if($retval == 2){
$reguname = $HTTP_POST_VARS['user'];//$HTTP_SESSION_VARS['reguname'] = $HTTP_POST_VARS['user']; //
$regsuccess = false;//$HTTP_SESSION_VARS['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;
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
global $forgotpass;
global $reguname,$regsuccess;
global $value_array,$error_array;
session_start();
/* Username error checking */
$subuser = $HTTP_POST_VARS['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 ||
!eregi("^([0-9a-z])+$", $subuser) ||
(!$database->usernameTaken($subuser))){
$form->setError($field, "* Username does not exist
");
}
}
/* Errors exist, have user correct them */
if($form->num_errors > 0){
$value_array = $HTTP_POST_VARS;// $HTTP_SESSION_VARS['value_array'] = $HTTP_POST_VARS; //
$error_array = $form->getErrorArray(); //$HTTP_SESSION_VARS['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'];
/* Attempt to send the email with new password */
if($mailer->sendNewPass($subuser,$email,$newpass)){
/* Email sent, update database */
$database->updateUserField($subuser, "password", md5($newpass));
$forgotpass = true;//$HTTP_SESSION_VARS['forgotpass'] = true; //
}
/* Email failure, do not change password */
else{
$forgotpass = false; // $HTTP_SESSION_VARS['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;
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_SESSION_VARS,$HTTP_COOKIE_VARS;
global $useredit;
global $forgotpass;
global $reguname,$regsuccess;
global $value_array,$error_array;
session_start();
/* Account edit attempt */
$retval = $session->editAccount($HTTP_POST_VARS['curpass'], $HTTP_POST_VARS['newpass'], $HTTP_POST_VARS['newpass_confirm'], $HTTP_POST_VARS['email'], $HTTP_POST_VARS['sex'], $HTTP_POST_VARS['country'], $HTTP_POST_VARS['newsletter']);
/* Account edit successful */
if($retval){
$useredit = true;//$HTTP_SESSION_VARS['useredit'] = true;
header("Location:".$session->referrer);
}
/* Error found with form */
else{
$value_array = $HTTP_POST_VARS;//$HTTP_SESSION_VARS['value_array'] = $HTTP_POST_VARS;
$error_array = $form->getErrorArray();//$HTTP_SESSION_VARS['error_array'] = $form->getErrorArray();
header("Location:".$session->referrer);
}
}
};
/* Initialize process */
$process = new Process;
?>