From 77b34e1b2703c32330d179eb4e387cf6dd39ec11 Mon Sep 17 00:00:00 2001 From: Brad Shuttleworth Date: Mon, 28 Nov 2005 18:32:05 +0000 Subject: [PATCH] moved login page to newui. --- presentation/login.php | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------- resources/css/kt-login.css | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ templates/ktcore/login.smarty | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+), 104 deletions(-) create mode 100644 resources/css/kt-login.css create mode 100644 templates/ktcore/login.smarty diff --git a/presentation/login.php b/presentation/login.php index f58d766..53d06dc 100644 --- a/presentation/login.php +++ b/presentation/login.php @@ -2,8 +2,11 @@ // main library routines and defaults require_once("../config/dmsDefaults.php"); -require_once("../lib/util/sanitize.inc"); -require_once(KT_DIR . "/presentation/Html.inc"); +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); +require_once(KT_LIB_DIR . '/session/control.inc'); +require_once(KT_LIB_DIR . '/session/Session.inc'); +require_once(KT_LIB_DIR . '/users/User.inc'); + /** * $Id$ * @@ -30,101 +33,95 @@ require_once(KT_DIR . "/presentation/Html.inc"); * @author Michael Joseph , Jam Warehouse (Pty) Ltd, South Africa */ -global $default; - -$redirect = $_REQUEST['redirect']; -$errorMessage = $_REQUEST['errorMessage']; +class LoginPageDispatcher extends KTDispatcher { -if ($_REQUEST['loginAction'] == "loginForm") { - // TODO: build login form using PatternMainPage - $cookietest = KTUtil::randomString(); - setcookie("CookieTestCookie", $cookietest, false); - print " - - uiUrl/stylesheet.php\"> - graphicsUrl/tree.ico\"> - The KnowledgeTree - - - - - -
- graphicsUrl/ktLogin.jpg\"> -

- \n - - - - - \t - \t - - - \n - \n - \n - -
" . _("Please enter your details below to login") . "
" . sanitize($errorMessage) . "
- \t
" . _("Username") . ":
" . _("Password") . ":
-
" . _("System Version") . ": " . $default->systemVersion . "
-
- - "; - -} elseif ($_REQUEST['loginAction'] == "login") { - // set default url for login failure - // with redirect appended if set - $url = $url . "login.php?loginAction=loginForm" . (isset($redirect) ? "&redirect=" . urlencode($redirect) : ""); - $cookieTest = KTUtil::arrayGet($_COOKIE, "CookieTestCookie", null); - if (is_null($cookieTest) || $cookieTest != KTUtil::arrayGet($_REQUEST, "cookietestinput")) { - $url .= "&errorMessage=" . urlencode(_("KnowledgeTree requires cookies to work")); - redirect($url); - exit(0); - } - - // if requirements are met and we have a username and password to authenticate - if (isset($_REQUEST['fUserName']) && isset($_REQUEST['fPassword']) ) { - // verifies the login and password of the user - $dbAuth = new $default->authenticationClass; - $userDetails = $dbAuth->login($_REQUEST['fUserName'], $_REQUEST['fPassword']); + function do_main() { + $this->check(); // bounce here, potentially. + + $cookietest = KTUtil::randomString(); + setcookie("CookieTestCookie", $cookietest, false); + + $errorMessage = KTUtil::arrayGet($_REQUEST, 'errorMessage'); + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/login"); + $aTemplateData = array( + "context" => $this, + 'cookietest' => $cookietest, + 'errorMessage' => $errorMessage, + ); + return $oTemplate->render($aTemplateData); + } + + function simpleRedirectToMain($errorMessage, $url, $params) { + $params[] = 'errorMessage='. urlencode($errorMessage); + $url .= '?' . join('&', $params); + redirect($url); + exit(0); + } + + function do_login() { + $this->check(); + global $default; + + $redirect = KTUtil::arrayGet($_REQUEST, 'redirect'); + + $url = $_SERVER["PHP_SELF"]; + $queryParams = array(); + + if ($redirect !== null) { + $queryParams[] = 'redirect='. urlencode($redirect); + } + + + $cookieTest = KTUtil::arrayGet($_COOKIE, "CookieTestCookie", null); + $cookieVerify = KTUtil::arrayGet($_REQUEST, 'cookieverify', null); + + if (($cookieVerify === null) || ($cookieTest !== $cookieVerify)) { + $this->simpleRedirectToMain('You must have cookies enabled to use the KnowledgeTree.', $url, $params); + exit(0); + } + + $username = KTUtil::arrayGet($_REQUEST,'username'); + $password = KTUtil::arrayGet($_REQUEST,'password'); + + if (empty($username)) { + $this->simpleRedirectToMain('Please enter your username.', $url, $params); + } + + if (empty($password)) { + $this->simpleRedirectToMain('Please enter your username.', $url, $params); + } + + $dbAuth = new $default->authenticationClass; // $default. urk. + $userDetails = $dbAuth->login($username, $password); + + switch ($userDetails["status"]) { - // bad credentials - case 0: - $url = $url . "&errorMessage=" . urlencode(_("Login failure")); - break; - // successfully authenticated - case 1: + case 0: // bad credentials + $this->simpleRedirectToMain('Login failed. Please check your username and password, and try again.', $url, $params); + break; + case 1: // successfully authenticated // start the session $session = new Session(); $sessionID = $session->create($userDetails["userID"]); - // initialise page-level authorisation array - $_SESSION["pageAccess"] = NULL; + // DEPRECATED initialise page-level authorisation array + $_SESSION["pageAccess"] = NULL; // check for a location to forward to - if (isset($redirect) && strlen(trim($redirect))>0) { + if ($redirect !== null) { // remove any params from redirect before looking up from sitemap if (strstr($redirect, "?")) { $queryString = substr($redirect, strpos($redirect, "?")+1, strlen($redirect)); @@ -142,38 +139,34 @@ if ($_REQUEST['loginAction'] == "loginForm") { // default to the dashboard $url = generateControllerUrl("dashboard"); } - // else redirect to the dashboard if there is none } else { $url = generateControllerUrl("dashboard"); } + exit(redirect($url)); break; // login disabled case 2: - $url = $url . "&errorMessage=" . urlencode(_("Account has been DISABLED, contact the System Adminstrator")); + $this->simpleRedirectToMain("Account has been DISABLED, contact the System Adminstrator", $url, $params); break; // too many sessions case 3 : - $url = $url . "&errorMessage=" . urlencode(_("Maximum sessions for user reached.
Contact the System Administrator")); + $this->simpleRedirectToMain(_("Maximum sessions for user reached.
Contact the System Administrator"), $url, $params); break; // not a unit user case 4 : - $url = $url . "&errorMessage=" . urlencode(_("This user does not belong to a group and is therefore not allowed to log in.")); + $this->simpleRedirectToMain(_("This user does not belong to a group and is therefore not allowed to log in."), $url, $params);; break; default : - $url = $url . "&errorMessage=" . urlencode(_("Login failure")); - } - } else { - // didn't receive any login parameters, so redirect login form - $default->log->error("login.php no login parameters received"); - } - if (strlen($queryString) > 0) { - $url .= "&$queryString"; - } - redirect($url); -} else { - // redirect to root - $url = generateLink("", ""); - redirect($url); + $this->simpleRedirectToMain(_("Login failure"), $url, $params); + } + // we should not get here. + $this->simpleRedirectToMain(_("Unable to start session. Please contact the administrator."), $url, $params); + } } -?> + + +$dispatcher =& new LoginPageDispatcher(); +$dispatcher->dispatch(); + +?> \ No newline at end of file diff --git a/resources/css/kt-login.css b/resources/css/kt-login.css new file mode 100644 index 0000000..5cf6887 --- /dev/null +++ b/resources/css/kt-login.css @@ -0,0 +1,62 @@ + + body { + font-family: sans-serif; + font-size: small; + margin-top: 8em; + text-align: center; + } + + label { + font-weight: bold; + display: block; + margin: 0.5em 0; + } + + #loginbox { + padding: 1em; + width: 252px; + border: 1px solid #ccc; + margin-left: auto; + margin-right: auto; + text-align: left; + } + + input { + border: 1px solid #666; + width: 252px; + } + + .logoimage { + margin-bottom: 2em; + } + + .form_actions { + margin-top: 1em; + padding-top: 1em; + border-top: 1px solid #eee; + text-align: right; + } + + .form_actions input { + width: auto; + } + +.descriptiveText +{ + color: #666; +} + + +/* block level. */ +.ktError +{ + padding: 0 1em; + border: 1px solid #ffc21e; + margin: 0.5em 0; + background: #ffdd80; +} + +.ktError p { + padding-left: 25px; + background: transparent url(/thirdparty/icon-theme/16x16/status/dialog-warning.png) center left no-repeat; +} diff --git a/templates/ktcore/login.smarty b/templates/ktcore/login.smarty new file mode 100644 index 0000000..c3e601d --- /dev/null +++ b/templates/ktcore/login.smarty @@ -0,0 +1,36 @@ + + + + Login | KnowledgeTree + + + + + + +
+ + + + KnowledgeTree DMS
+ {if ($errorMessage == null)} +

Please enter your details below to login.

+ {else} +

{$errorMessage}

+ {/if} + + + + + + + +
+ +
+ +
+ + + \ No newline at end of file -- libgit2 0.21.4