Location: PHPKode > scripts > PHPMass Shopping Cart > phpmass-shopping-cart/user/login.php
<?php
/******************************************************************
 * PHPMass Shopping Cart
 * The contents of this file are subject to the PHPMass License. 
 * If you do not agree with PHPMass License Terms and Conditions 
 * than you should not use this software.
 * A copy of the license file is available on www.phpmass.com/license.htm page.
 * 
 * PHPMass.com.
 * All Rights Reserved.
 ******************************************************************/
$SiteSection = 'front';
require('../includes/config.php');
$Admins->logout();

// Cart and top products
$LastProducts = $Carts->getLastProducts();
if (is_array($LastProducts)) {
	$LastProduct = array_shift($LastProducts);
}
$smarty->assign('LastProduct', $LastProduct);
$smarty->assign('LastProducts', $LastProducts);

$TopProducts = $Categories->getTopProducts(0,false,true);
$smarty->assign('TopProducts', $TopProducts);

// END Cart and top products


if (isset($_POST['Login'])) {

	if (!hasLength($_POST['UserName'],4,20)  || !isUserName($_POST['UserName'])) {
		$Error['Username_Length'] = $Lang['Username_Length'];
	}
	elseif (!hasLength($_POST['Password'],4,20)){
		$Error['Password_Length'] = $Lang['Password_Length'];
	}
	elseif ($Users->login($_POST['UserName'],$_POST['Password'])) {
		$Session->setcookie('PHPSESSID',$Session->getcookie('PHPSESSID'));

		//Set variables in session
		$Session->set_var('logedin',true);
		$Session->set_var('userid',$Users->logedUserID);
		$Session->set_var('username',$Users->logedUserName);
		$Session->set_var('fullname',$Users->logedUserFullName);
		$Session->set_var('pid',$Users->logedUserPid);
		$Session->set_var('ipaddress',$_SERVER['REMOTE_ADDR']);

		if ($Session->getcookie('referer')) {
			$Session->delcookie('referer');
			Redirect302('Location: '.$Session->getcookie('referer'));
			exit();
		}
		else {
			Redirect302('Location: /user/');
			exit();
		}

	}
	elseif($Users->usernameExists($_POST['UserName'])) {
		$Error['UserName_Exists'] = $Lang['UserName_Exists'];
		if($Users->usernameIsValid($_POST['UserName']))
		$Error['User_NotValidated'] = $Lang['User_NotValidated'];
	}
	else $Error['UserName_NotExists'] = $Lang['UserName_NotExists'];
}
if (isset($_POST['register'])) {
	if (!$Captcha->verifyCaptcha($_POST['cvcode'])) $Error['Captcha_Fail'] = $Lang['Captcha_Fail'];
	if (!isEmail($_POST['email'])) $Error['Email_NotValid'] = $Lang['Email_NotValid'];
	if (!isName($_POST['fullname'])) $Error['FullName_NotValid'] = $Lang['FullName_NotValid'];
	if (!isUserName($_POST['newusername'])) $Error['Username_Length'] = $Lang['Username_Length'];
	if ($_POST['newpassword'] != $_POST['paswordagain']) $Error['Passwords_TheSame'] = $Lang['Passwords_TheSame'];
	if (!hasLength($_POST['newpassword'],4,20) || !hasLength($_POST['paswordagain'],4,20)) $Error['Password_Length'] = $Lang['Password_Length'];
	if (!isPhone($_POST['phone'])) $Error['Phone_NotValid'] = $Lang['Phone_NotValid'];
	if ($Users->usernameExists($_POST['newusername'])) $Error['Username_AlreadyExists'] = $Lang['Username_AlreadyExists'];
	if ($Users->emailExists($_POST['email'])) $Error['Email_AlreadyExists'] = $Lang['Email_AlreadyExists'];
	if (!$Error) {
		$Users->newUsername($_POST['newusername'],$_POST['fullname'],$_POST['email'],$_POST['newpassword'],$_POST['phone']);
		$smarty->assign('Registered', 'True');
	}
}
if (isset($_GET['activate'])){
	$parts = explode('-',$_GET['activate']);
	if ($Users->activateUserByKey($parts[0],$parts[1])) $InfoMessage['User_Validated'] = $Lang['User_Validated'];
	else $Error['Wrong_Validation_Key'] = $Lang['Wrong_Validation_Key'];
}
if (isset($_GET['reset'])){
	$parts = explode('-',$_GET['reset']);
	if (!$Users->isKeyUser($parts[0],$parts[1])){
		$smarty->assign('wrong', 'true');
		$Error['Incorect_Key'] = $Lang['Incorect_Key'];
	}
	else {
		if ($_POST['Submit']){
			if ($_POST['newpassword'] != $_POST['passwordagain']) $Error['Passwords_TheSame'] = $Lang['Passwords_TheSame'];
			if (!hasLength($_POST['newpassword'],4,20) || !hasLength($_POST['passwordagain'],4,20)) $Error['Password_Length'] = $Lang['Password_Length'];
			if (!$Error) {
				$Users->changePasswordByKey($parts[0],$_POST['newpassword']);
				Redirect302('Location: /user/login.php');
			}
			else $InfoMessage['Nothing_Changed'] = $Lang['Nothing_Changed'];
		}
		$UserInfo = $Users->getUser($parts[0]);
		$smarty->assign('username', $UserInfo['username']);
		$smarty->assign('fullname', $UserInfo['fullname']);
	}
	$smarty->assign('reset', 'True');
}
if ($Session->get_var('logedin') == TRUE)  {
	Redirect302('Location: /');
}

$Categories->setCategory(0);
$smarty->assign('CategoryTree', $Categories->getHomeTree());
$smarty->assign('Manufacturers', $Manufacturers->getManufacturers());
$smarty->assign('TopSearches', $search->getTopSearches($_GET['url']));
$smarty->assign('POST', removeSafeQuote($_POST));
$smarty->assign('GET', $_GET);

$smarty->assign('PageTitle', 'Login');
$smarty->assign('Error', $Error);
$smarty->assign('InfoMessage', $InfoMessage);
$smarty->display(DOC_ROOT.'/skin/templates/user/'.'login.tpl');
?>
Return current item: PHPMass Shopping Cart