Commit c76c56e7457816955b6ca567617a017c234bc021

Authored by Neil Blakey-Milner
1 parent 7e47c0bd

Add login interceptors and a more dynamic login process.

(Forgot this file in last commit)


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5874 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 87 additions and 14 deletions
login.php
@@ -9,6 +9,7 @@ require_once(KT_LIB_DIR . '/users/User.inc'); @@ -9,6 +9,7 @@ require_once(KT_LIB_DIR . '/users/User.inc');
9 require_once(KT_LIB_DIR . '/authentication/authenticationutil.inc.php'); 9 require_once(KT_LIB_DIR . '/authentication/authenticationutil.inc.php');
10 require_once(KT_LIB_DIR . '/help/help.inc.php'); 10 require_once(KT_LIB_DIR . '/help/help.inc.php');
11 require_once(KT_LIB_DIR . '/help/helpreplacement.inc.php'); 11 require_once(KT_LIB_DIR . '/help/helpreplacement.inc.php');
  12 +require_once(KT_LIB_DIR . '/authentication/interceptorregistry.inc.php');
12 13
13 /** 14 /**
14 * $Id$ 15 * $Id$
@@ -69,8 +70,46 @@ class LoginPageDispatcher extends KTDispatcher { @@ -69,8 +70,46 @@ class LoginPageDispatcher extends KTDispatcher {
69 exit(0); 70 exit(0);
70 } 71 }
71 72
  73 + function performLogin(&$oUser) {
  74 + $session = new Session();
  75 + $sessionID = $session->create($oUser);
  76 +
  77 + $redirect = KTUtil::arrayGet($_REQUEST, 'redirect');
  78 +
  79 + // DEPRECATED initialise page-level authorisation array
  80 + $_SESSION["pageAccess"] = NULL;
  81 +
  82 + $cookietest = KTUtil::randomString();
  83 + setcookie("CookieTestCookie", $cookietest, 0);
  84 +
  85 + $this->redirectTo('checkCookie', array(
  86 + 'cookieVerify' => $cookietest,
  87 + 'redirect' => $redirect,
  88 + ));
  89 + exit(0);
  90 + }
  91 +
72 function do_main() { 92 function do_main() {
73 global $default; 93 global $default;
  94 +
  95 + $oUser =& KTInterceptorRegistry::checkInterceptorsForAuthenticated();
  96 + if (is_a($oUser, 'User')) {
  97 + $this->performLogin($oUser);
  98 + }
  99 + if (is_array($oUser) && count($oUser)) {
  100 + if (empty($_REQUEST['errorMessage'])) {
  101 + $_REQUEST['errorMessage'] = array();
  102 + } else {
  103 + $_REQUEST['errorMessage'] = array($_REQUEST['errorMessage']);
  104 + }
  105 + foreach ($oUser as $oError) {
  106 + $_REQUEST['errorMessage'][] = $oError->getMessage();
  107 + }
  108 + $_REQUEST['errorMessage'] = join('. <br /> ', $_REQUEST['errorMessage']);
  109 + }
  110 +
  111 +
  112 + KTInterceptorRegistry::checkInterceptorsForTakeOver();
74 113
75 $this->check(); // bounce here, potentially. 114 $this->check(); // bounce here, potentially.
76 header('Content-type: text/html; charset=UTF-8'); 115 header('Content-type: text/html; charset=UTF-8');
@@ -117,6 +156,21 @@ class LoginPageDispatcher extends KTDispatcher { @@ -117,6 +156,21 @@ class LoginPageDispatcher extends KTDispatcher {
117 } 156 }
118 157
119 function do_login() { 158 function do_login() {
  159 + $aExtra = array();
  160 + $oUser =& KTInterceptorRegistry::checkInterceptorsForAuthenticated();
  161 + if (is_a($oUser, 'User')) {
  162 + $this->performLogin($oUser);
  163 + }
  164 + if (is_array($oUser)) {
  165 + foreach ($oUser as $oError) {
  166 + if (is_a($oError, 'KTNoLocalUser')) {
  167 + $aExtra = kt_array_merge($aExtra, $oError->aExtra);
  168 + }
  169 + }
  170 + }
  171 +
  172 + KTInterceptorRegistry::checkInterceptorsForTakeOver();
  173 +
120 $this->check(); 174 $this->check();
121 global $default; 175 global $default;
122 176
@@ -142,12 +196,15 @@ class LoginPageDispatcher extends KTDispatcher { @@ -142,12 +196,15 @@ class LoginPageDispatcher extends KTDispatcher {
142 $this->simpleRedirectToMain(_kt('Please enter your username.'), $url, $queryParams); 196 $this->simpleRedirectToMain(_kt('Please enter your username.'), $url, $queryParams);
143 } 197 }
144 198
145 - if (empty($password)) {  
146 - $this->simpleRedirectToMain(_kt('Please enter your password.'), $url, $queryParams);  
147 - } 199 + #if (empty($password)) {
  200 + # $this->simpleRedirectToMain(_kt('Please enter your password.'), $url, $queryParams);
  201 + #}
148 202
149 $oUser =& User::getByUsername($username); 203 $oUser =& User::getByUsername($username);
150 if (PEAR::isError($oUser) || ($oUser === false)) { 204 if (PEAR::isError($oUser) || ($oUser === false)) {
  205 + if (is_a($oUser, 'ktentitynoobjects')) {
  206 + $this->handleUserDoesNotExist($username, $aExtra);
  207 + }
151 $this->simpleRedirectToMain(_kt('Login failed. Please check your username and password, and try again.'), $url, $queryParams); 208 $this->simpleRedirectToMain(_kt('Login failed. Please check your username and password, and try again.'), $url, $queryParams);
152 exit(0); 209 exit(0);
153 } 210 }
@@ -163,19 +220,35 @@ class LoginPageDispatcher extends KTDispatcher { @@ -163,19 +220,35 @@ class LoginPageDispatcher extends KTDispatcher {
163 exit(0); 220 exit(0);
164 } 221 }
165 222
166 - $session = new Session();  
167 - $sessionID = $session->create($oUser);  
168 -  
169 - // DEPRECATED initialise page-level authorisation array  
170 - $_SESSION["pageAccess"] = NULL; 223 + $this->performLogin($oUser);
  224 + }
171 225
172 - $cookietest = KTUtil::randomString();  
173 - setcookie("CookieTestCookie", $cookietest, 0); 226 + function handleUserDoesNotExist($username, $aExtra = null) {
  227 + if (empty($aExtra)) {
  228 + $aExtra = array();
  229 + }
  230 + $res = KTAuthenticationUtil::autoSignup($username, $aExtra);
  231 + if (empty($res)) {
  232 + return $res;
  233 + }
  234 + if (is_a($res, 'User')) {
  235 + $this->performLogin($oUser);
  236 + }
  237 + if (is_a($res, 'KTAuthenticationSource')) {
  238 + $_SESSION['autosignup'] = $aExtra;
  239 + $this->redirectTo('autoSignup', array(
  240 + 'source_id' => $res->getId(),
  241 + 'username' => $username,
  242 + ));
  243 + exit(0);
  244 + }
  245 + }
174 246
175 - $this->redirectTo('checkCookie', array(  
176 - 'cookieVerify' => $cookietest,  
177 - 'redirect' => $redirect,  
178 - )); 247 + function do_autoSignup() {
  248 + $oSource =& $this->oValidator->validateAuthenticationSource($_REQUEST['source_id']);
  249 + $oProvider =& KTAuthenticationUtil::getAuthenticationProviderForSource($oSource);
  250 + $oDispatcher = $oProvider->getSignupDispatcher($oSource);
  251 + $oDispatcher->subDispatch($this);
179 exit(0); 252 exit(0);
180 } 253 }
181 254