Commit 77b34e1b2703c32330d179eb4e387cf6dd39ec11
1 parent
f4d46d73
moved login page to newui.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4231 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
195 additions
and
104 deletions
presentation/login.php
| @@ -2,8 +2,11 @@ | @@ -2,8 +2,11 @@ | ||
| 2 | 2 | ||
| 3 | // main library routines and defaults | 3 | // main library routines and defaults |
| 4 | require_once("../config/dmsDefaults.php"); | 4 | require_once("../config/dmsDefaults.php"); |
| 5 | -require_once("../lib/util/sanitize.inc"); | ||
| 6 | -require_once(KT_DIR . "/presentation/Html.inc"); | 5 | +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); |
| 6 | +require_once(KT_LIB_DIR . '/session/control.inc'); | ||
| 7 | +require_once(KT_LIB_DIR . '/session/Session.inc'); | ||
| 8 | +require_once(KT_LIB_DIR . '/users/User.inc'); | ||
| 9 | + | ||
| 7 | /** | 10 | /** |
| 8 | * $Id$ | 11 | * $Id$ |
| 9 | * | 12 | * |
| @@ -30,101 +33,95 @@ require_once(KT_DIR . "/presentation/Html.inc"); | @@ -30,101 +33,95 @@ require_once(KT_DIR . "/presentation/Html.inc"); | ||
| 30 | * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | 33 | * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa |
| 31 | */ | 34 | */ |
| 32 | 35 | ||
| 33 | -global $default; | ||
| 34 | - | ||
| 35 | -$redirect = $_REQUEST['redirect']; | ||
| 36 | -$errorMessage = $_REQUEST['errorMessage']; | 36 | +class LoginPageDispatcher extends KTDispatcher { |
| 37 | 37 | ||
| 38 | -if ($_REQUEST['loginAction'] == "loginForm") { | ||
| 39 | - // TODO: build login form using PatternMainPage | ||
| 40 | - $cookietest = KTUtil::randomString(); | ||
| 41 | - setcookie("CookieTestCookie", $cookietest, false); | ||
| 42 | - print "<html> | ||
| 43 | - <head> | ||
| 44 | - <link rel=\"stylesheet\" href=\"$default->uiUrl/stylesheet.php\"> | ||
| 45 | - <link rel=\"SHORTCUT ICON\" href=\"$default->graphicsUrl/tree.ico\"> | ||
| 46 | - <title>The KnowledgeTree</title> | ||
| 47 | - | ||
| 48 | - <SCRIPT TYPE=\"text/javascript\"> | ||
| 49 | - <!-- | ||
| 50 | - function submitenter(myfield,e) { | ||
| 51 | - var keycode; | ||
| 52 | - if (window.event) { | ||
| 53 | - keycode = window.event.keyCode; | ||
| 54 | - } else if (e) { | ||
| 55 | - keycode = e.which; | ||
| 56 | - } else { | ||
| 57 | - return true; | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - if (keycode == 13) { | ||
| 61 | - myfield.form.submit(); | ||
| 62 | - return false; | 38 | + function check() { |
| 39 | + // bounce out immediately. | ||
| 40 | + $session = new Session(); | ||
| 41 | + if ($session->verify() == 1) { // erk. neil - DOUBLE CHECK THIS PLEASE. | ||
| 42 | + exit(redirect(generateControllerLink('dashboard'))); | ||
| 63 | } else { | 43 | } else { |
| 64 | - return true; | 44 | + $session->destroy(); // toast it - its probably a hostile session. |
| 65 | } | 45 | } |
| 46 | + return true; | ||
| 66 | } | 47 | } |
| 67 | - //--> | ||
| 68 | - </SCRIPT> | ||
| 69 | - | ||
| 70 | - </head> | ||
| 71 | - <body onload=\"javascript:document.loginForm.fUserName.focus()\"> | ||
| 72 | - <center> | ||
| 73 | - <img src=\"$default->graphicsUrl/ktLogin.jpg\"> | ||
| 74 | - <br><br> | ||
| 75 | - <table>\n | ||
| 76 | - <form name=\"loginForm\" action=\"" . $_SERVER["PHP_SELF"] . "\" method=\"post\"> | ||
| 77 | - <tr><td>" . _("Please enter your details below to login") . "</td></tr> | ||
| 78 | - <tr><td></td></tr> | ||
| 79 | - <tr><td><font color=\"red\">" . sanitize($errorMessage) . "</font><tr><td> | ||
| 80 | - \t<tr><td>" . _("Username") . ":</td></tr> | ||
| 81 | - \t<tr><td><input type=\"text\" name=\"fUserName\" size=\"35\"></td></tr> | ||
| 82 | - \t<tr><td>" . _("Password") . ":</td></tr> | ||
| 83 | - <tr><td><input type=\"password\" name=\"fPassword\" size=\"35\" onKeyPress=\"return submitenter(this,event)\"> | ||
| 84 | - </td></tr> | ||
| 85 | - <input type=\"hidden\" name=\"redirect\" value=\"$redirect\"/> | ||
| 86 | - <input type=\"hidden\" name=\"loginAction\" value=\"login\">\n | ||
| 87 | - <input type=\"hidden\" name=\"cookietestinput\" value=\"$cookietest\">\n | ||
| 88 | - <tr align=\"right\"><td><input type=\"image\" src=\"" . KTHtml::getLoginButton() . "\" border=\"0\"></td></tr>\n | ||
| 89 | - <tr><td><font size=\"1\">" . _("System Version") . ": " . $default->systemVersion . "</font></td></tr> | ||
| 90 | - </table> | ||
| 91 | - </center> | ||
| 92 | - </body> | ||
| 93 | - </html>"; | ||
| 94 | - | ||
| 95 | -} elseif ($_REQUEST['loginAction'] == "login") { | ||
| 96 | - // set default url for login failure | ||
| 97 | - // with redirect appended if set | ||
| 98 | - $url = $url . "login.php?loginAction=loginForm" . (isset($redirect) ? "&redirect=" . urlencode($redirect) : ""); | ||
| 99 | - $cookieTest = KTUtil::arrayGet($_COOKIE, "CookieTestCookie", null); | ||
| 100 | - if (is_null($cookieTest) || $cookieTest != KTUtil::arrayGet($_REQUEST, "cookietestinput")) { | ||
| 101 | - $url .= "&errorMessage=" . urlencode(_("KnowledgeTree requires cookies to work")); | ||
| 102 | - redirect($url); | ||
| 103 | - exit(0); | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - // if requirements are met and we have a username and password to authenticate | ||
| 107 | - if (isset($_REQUEST['fUserName']) && isset($_REQUEST['fPassword']) ) { | ||
| 108 | - // verifies the login and password of the user | ||
| 109 | - $dbAuth = new $default->authenticationClass; | ||
| 110 | - $userDetails = $dbAuth->login($_REQUEST['fUserName'], $_REQUEST['fPassword']); | ||
| 111 | 48 | ||
| 49 | + function do_main() { | ||
| 50 | + $this->check(); // bounce here, potentially. | ||
| 51 | + | ||
| 52 | + $cookietest = KTUtil::randomString(); | ||
| 53 | + setcookie("CookieTestCookie", $cookietest, false); | ||
| 54 | + | ||
| 55 | + $errorMessage = KTUtil::arrayGet($_REQUEST, 'errorMessage'); | ||
| 56 | + | ||
| 57 | + $oTemplating = new KTTemplating; | ||
| 58 | + $oTemplate = $oTemplating->loadTemplate("ktcore/login"); | ||
| 59 | + $aTemplateData = array( | ||
| 60 | + "context" => $this, | ||
| 61 | + 'cookietest' => $cookietest, | ||
| 62 | + 'errorMessage' => $errorMessage, | ||
| 63 | + ); | ||
| 64 | + return $oTemplate->render($aTemplateData); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + function simpleRedirectToMain($errorMessage, $url, $params) { | ||
| 68 | + $params[] = 'errorMessage='. urlencode($errorMessage); | ||
| 69 | + $url .= '?' . join('&', $params); | ||
| 70 | + redirect($url); | ||
| 71 | + exit(0); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + function do_login() { | ||
| 75 | + $this->check(); | ||
| 76 | + global $default; | ||
| 77 | + | ||
| 78 | + $redirect = KTUtil::arrayGet($_REQUEST, 'redirect'); | ||
| 79 | + | ||
| 80 | + $url = $_SERVER["PHP_SELF"]; | ||
| 81 | + $queryParams = array(); | ||
| 82 | + | ||
| 83 | + if ($redirect !== null) { | ||
| 84 | + $queryParams[] = 'redirect='. urlencode($redirect); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + | ||
| 88 | + $cookieTest = KTUtil::arrayGet($_COOKIE, "CookieTestCookie", null); | ||
| 89 | + $cookieVerify = KTUtil::arrayGet($_REQUEST, 'cookieverify', null); | ||
| 90 | + | ||
| 91 | + if (($cookieVerify === null) || ($cookieTest !== $cookieVerify)) { | ||
| 92 | + $this->simpleRedirectToMain('You must have cookies enabled to use the KnowledgeTree.', $url, $params); | ||
| 93 | + exit(0); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + $username = KTUtil::arrayGet($_REQUEST,'username'); | ||
| 97 | + $password = KTUtil::arrayGet($_REQUEST,'password'); | ||
| 98 | + | ||
| 99 | + if (empty($username)) { | ||
| 100 | + $this->simpleRedirectToMain('Please enter your username.', $url, $params); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + if (empty($password)) { | ||
| 104 | + $this->simpleRedirectToMain('Please enter your username.', $url, $params); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + $dbAuth = new $default->authenticationClass; // $default. urk. | ||
| 108 | + $userDetails = $dbAuth->login($username, $password); | ||
| 109 | + | ||
| 110 | + | ||
| 112 | switch ($userDetails["status"]) { | 111 | switch ($userDetails["status"]) { |
| 113 | - // bad credentials | ||
| 114 | - case 0: | ||
| 115 | - $url = $url . "&errorMessage=" . urlencode(_("Login failure")); | ||
| 116 | - break; | ||
| 117 | - // successfully authenticated | ||
| 118 | - case 1: | 112 | + case 0: // bad credentials |
| 113 | + $this->simpleRedirectToMain('Login failed. Please check your username and password, and try again.', $url, $params); | ||
| 114 | + break; | ||
| 115 | + case 1: // successfully authenticated | ||
| 119 | // start the session | 116 | // start the session |
| 120 | $session = new Session(); | 117 | $session = new Session(); |
| 121 | $sessionID = $session->create($userDetails["userID"]); | 118 | $sessionID = $session->create($userDetails["userID"]); |
| 122 | 119 | ||
| 123 | - // initialise page-level authorisation array | ||
| 124 | - $_SESSION["pageAccess"] = NULL; | 120 | + // DEPRECATED initialise page-level authorisation array |
| 121 | + $_SESSION["pageAccess"] = NULL; | ||
| 125 | 122 | ||
| 126 | // check for a location to forward to | 123 | // check for a location to forward to |
| 127 | - if (isset($redirect) && strlen(trim($redirect))>0) { | 124 | + if ($redirect !== null) { |
| 128 | // remove any params from redirect before looking up from sitemap | 125 | // remove any params from redirect before looking up from sitemap |
| 129 | if (strstr($redirect, "?")) { | 126 | if (strstr($redirect, "?")) { |
| 130 | $queryString = substr($redirect, strpos($redirect, "?")+1, strlen($redirect)); | 127 | $queryString = substr($redirect, strpos($redirect, "?")+1, strlen($redirect)); |
| @@ -142,38 +139,34 @@ if ($_REQUEST['loginAction'] == "loginForm") { | @@ -142,38 +139,34 @@ if ($_REQUEST['loginAction'] == "loginForm") { | ||
| 142 | // default to the dashboard | 139 | // default to the dashboard |
| 143 | $url = generateControllerUrl("dashboard"); | 140 | $url = generateControllerUrl("dashboard"); |
| 144 | } | 141 | } |
| 145 | - | ||
| 146 | // else redirect to the dashboard if there is none | 142 | // else redirect to the dashboard if there is none |
| 147 | } else { | 143 | } else { |
| 148 | $url = generateControllerUrl("dashboard"); | 144 | $url = generateControllerUrl("dashboard"); |
| 149 | } | 145 | } |
| 146 | + exit(redirect($url)); | ||
| 150 | break; | 147 | break; |
| 151 | // login disabled | 148 | // login disabled |
| 152 | case 2: | 149 | case 2: |
| 153 | - $url = $url . "&errorMessage=" . urlencode(_("Account has been DISABLED, contact the System Adminstrator")); | 150 | + $this->simpleRedirectToMain("Account has been DISABLED, contact the System Adminstrator", $url, $params); |
| 154 | break; | 151 | break; |
| 155 | // too many sessions | 152 | // too many sessions |
| 156 | case 3 : | 153 | case 3 : |
| 157 | - $url = $url . "&errorMessage=" . urlencode(_("Maximum sessions for user reached.<br>Contact the System Administrator")); | 154 | + $this->simpleRedirectToMain(_("Maximum sessions for user reached.<br>Contact the System Administrator"), $url, $params); |
| 158 | break; | 155 | break; |
| 159 | // not a unit user | 156 | // not a unit user |
| 160 | case 4 : | 157 | case 4 : |
| 161 | - $url = $url . "&errorMessage=" . urlencode(_("This user does not belong to a group and is therefore not allowed to log in.")); | 158 | + $this->simpleRedirectToMain(_("This user does not belong to a group and is therefore not allowed to log in."), $url, $params);; |
| 162 | break; | 159 | break; |
| 163 | default : | 160 | default : |
| 164 | - $url = $url . "&errorMessage=" . urlencode(_("Login failure")); | ||
| 165 | - } | ||
| 166 | - } else { | ||
| 167 | - // didn't receive any login parameters, so redirect login form | ||
| 168 | - $default->log->error("login.php no login parameters received"); | ||
| 169 | - } | ||
| 170 | - if (strlen($queryString) > 0) { | ||
| 171 | - $url .= "&$queryString"; | ||
| 172 | - } | ||
| 173 | - redirect($url); | ||
| 174 | -} else { | ||
| 175 | - // redirect to root | ||
| 176 | - $url = generateLink("", ""); | ||
| 177 | - redirect($url); | 161 | + $this->simpleRedirectToMain(_("Login failure"), $url, $params); |
| 162 | + } | ||
| 163 | + // we should not get here. | ||
| 164 | + $this->simpleRedirectToMain(_("Unable to start session. Please contact the administrator."), $url, $params); | ||
| 165 | + } | ||
| 178 | } | 166 | } |
| 179 | -?> | 167 | + |
| 168 | + | ||
| 169 | +$dispatcher =& new LoginPageDispatcher(); | ||
| 170 | +$dispatcher->dispatch(); | ||
| 171 | + | ||
| 172 | +?> | ||
| 180 | \ No newline at end of file | 173 | \ No newline at end of file |
resources/css/kt-login.css
0 → 100644
| 1 | + | ||
| 2 | + body { | ||
| 3 | + font-family: sans-serif; | ||
| 4 | + font-size: small; | ||
| 5 | + margin-top: 8em; | ||
| 6 | + text-align: center; | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + label { | ||
| 10 | + font-weight: bold; | ||
| 11 | + display: block; | ||
| 12 | + margin: 0.5em 0; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + #loginbox { | ||
| 16 | + padding: 1em; | ||
| 17 | + width: 252px; | ||
| 18 | + border: 1px solid #ccc; | ||
| 19 | + margin-left: auto; | ||
| 20 | + margin-right: auto; | ||
| 21 | + text-align: left; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + input { | ||
| 25 | + border: 1px solid #666; | ||
| 26 | + width: 252px; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + .logoimage { | ||
| 30 | + margin-bottom: 2em; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + .form_actions { | ||
| 34 | + margin-top: 1em; | ||
| 35 | + padding-top: 1em; | ||
| 36 | + border-top: 1px solid #eee; | ||
| 37 | + text-align: right; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + .form_actions input { | ||
| 41 | + width: auto; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | +.descriptiveText | ||
| 45 | +{ | ||
| 46 | + color: #666; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | + | ||
| 50 | +/* block level. */ | ||
| 51 | +.ktError | ||
| 52 | +{ | ||
| 53 | + padding: 0 1em; | ||
| 54 | + border: 1px solid #ffc21e; | ||
| 55 | + margin: 0.5em 0; | ||
| 56 | + background: #ffdd80; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +.ktError p { | ||
| 60 | + padding-left: 25px; | ||
| 61 | + background: transparent url(/thirdparty/icon-theme/16x16/status/dialog-warning.png) center left no-repeat; | ||
| 62 | +} |
templates/ktcore/login.smarty
0 → 100644
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
| 2 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| 3 | +<html> | ||
| 4 | +<head> | ||
| 5 | + <title>Login | KnowledgeTree</title> | ||
| 6 | + | ||
| 7 | + <link rel="stylesheet" href="{$rootUrl}/resources/css/kt-login.css" type="text/css" /> | ||
| 8 | + | ||
| 9 | +</head> | ||
| 10 | +<body> | ||
| 11 | + | ||
| 12 | + <div id="loginbox"> | ||
| 13 | + <form action="{$smarty.server.PHP_SELF}"> | ||
| 14 | + <input type="hidden" name="action" value="login" /> | ||
| 15 | + <input type="hidden" name="cookieverify" value="{$cookietest}" /> | ||
| 16 | + <img src="{$rootUrl}/resources/graphics/ktlogo-topbar-right.png" alt="KnowledgeTree DMS" class="logoimage" width="252" height="50"/><br /> | ||
| 17 | + {if ($errorMessage == null)} | ||
| 18 | + <p class="descriptiveText">Please enter your details below to login.</p> | ||
| 19 | + {else} | ||
| 20 | + <div class="ktError"><p>{$errorMessage}</p></div> | ||
| 21 | + {/if} | ||
| 22 | + | ||
| 23 | + <label for="username">Username</label> | ||
| 24 | + <input type="text" id="username" name="username"/> | ||
| 25 | + | ||
| 26 | + <label for="password">Password</label> | ||
| 27 | + <input type="password" id="password" name="password"/> | ||
| 28 | + | ||
| 29 | + <div class="form_actions"> | ||
| 30 | + <input type="submit" value="login" /> | ||
| 31 | + </div> | ||
| 32 | + </form> | ||
| 33 | + </div> | ||
| 34 | + | ||
| 35 | +</body> | ||
| 36 | +</html> | ||
| 0 | \ No newline at end of file | 37 | \ No newline at end of file |