, Jam Warehouse (Pty) Ltd, South Africa
* @package presentation
*/
// -------------------------------
// page start
// -------------------------------
global $default;
if ($loginAction == "loginForm") {
// TODO: build login form using PatternMainPage
print "
";
}
elseif ($loginAction == "login") {
// set default url for login failure
$url = $url . "login.php?loginAction=loginForm";
// if requirements are met and we have a username and password to authenticate
if( isset($fUserName) && isset($fPassword) ) {
// verifies the login and password of the user
$dbAuth = new $default->authenticationClass;
$userDetails = $dbAuth->login($fUserName, $fPassword);
switch ($userDetails["status"]) {
// bad credentials
case 0:
$url = $url . "&errorMessage=$lang_loginfail";
break;
// successfully authenticated
case 1:
// start the session
$session = new Session();
$sessionID = $session->create($userDetails["userID"]);
// initialise page-level authorisation array
$_SESSION["pageAccess"] = NULL;
// check for a location to forward to
if (isset($redirect) && strlen(trim($redirect))>0) {
// remove any params from redirect before looking up from sitemap
if (strstr($redirect, "?")) {
$queryString = substr($redirect, strpos($redirect, "?")+1, strlen($redirect));
$redirect = substr($redirect, 0, strpos($redirect, "?"));
$default->log->debug("login.php redirect=$redirect; querystring=$queryString");
}
// need to strip rootUrl off $redirect
if (strlen($default->rootUrl) > 0) {
$tmp = urldecode($redirect);
$default->log->debug("login.php: substr($tmp, strpos($tmp, $default->rootUrl)+strlen($default->rootUrl), strlen($tmp))");
$redirect = substr($tmp, strpos($tmp, $default->rootUrl)+strlen($default->rootUrl), strlen($tmp));
$default->log->debug("login.php: redirect=$redirect");
}
$action = $default->siteMap->getActionFromPage($redirect);
if ($action) {
$url = generateControllerUrl($action);
} else {
// default to the dashboard
$url = generateControllerUrl("dashboard");
}
// else redirect to the dashboard if there is none
} else {
$url = generateControllerUrl("dashboard");
}
break;
// login disabled
case 2:
$url = $url . "&errorMessage=" . urlencode($lang_logindisabled);
break;
// too many sessions
case 3 :
$url = $url . "&errorMessage=" . urlencode($lang_toomanysessions);
break;
default :
$url = $url . "&errorMessage=" . urlencode($lang_err_general);
}
} else {
// didn't receive any login parameters, so redirect login form
// TODO: set "no login parameters received error message?
// internal error message- should never happen
}
if (strlen($queryString) > 0) {
$url .= "&$queryString";
}
$default->log->debug("login.php: about to redirect to $url");
redirect($url);
}
?>