Create a new presentation object file named customer_login.php in the presentation folder, and add
the following to it:
class CustomerLogin
{
// Public stuff
public $mErrorMessage;
public $mLinkToLogin;
public $mLinkToRegisterCustomer;
public $mEmail = '';
CHAPTER 16 ?– MANAGING CUSTOMER DETAILS 510
// Class constructor
public function __construct()
{
if (USE_SSL == 'yes' && getenv('HTTPS') != 'on')
$this->mLinkToLogin =
Link::Build(str_replace(VIRTUAL_LOCATION, '', getenv('REQUEST_URI')),
'https');
else
$this->mLinkToLogin =
Link::Build(str_replace(VIRTUAL_LOCATION, '', getenv('REQUEST_URI')));
$this->mLinkToRegisterCustomer = Link::ToRegisterCustomer();
}
public function init()
{
// Decide if we have submitted
if (isset ($_POST['Login']))
{
// Get login status
$login_status = Customer::IsValid($_POST['email'], $_POST['password']);
switch ($login_status)
{
case 2:
$this->mErrorMessage = 'Unrecognized Email.';
$this->mEmail = $_POST['email'];
break;
case 1:
$this->mErrorMessage = 'Unrecognized password.';
$this->mEmail = $_POST['email'];
break;
case 0:
$redirect_to_link =
Link::Build(str_replace(VIRTUAL_LOCATION, '',
getenv('REQUEST_URI')));
header('Location:' . $redirect_to_link);
exit();
}
}
}
}
?>
CHAPTER 16 ?– MANAGING CUSTOMER DETAILS 511
3. Create a new template file named customer_logged.
Pages:
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629