Commit e287fc376326305733aacc1dcc58844bd5965d59

Authored by Megan
1 parent 6c73b7ec

KTS-4210 The code was being referenced incorrectly using an object call within a…

… statically called function. Moved the loginUtil code into the dispatcher and removed all static calls to it.
"Password Reset Plugin and AD Authentication"

Committed by: Megan Watson
Reviewed by: Kevin Cyster
plugins/passwordResetPlugin/loginResetDispatcher.php
... ... @@ -49,7 +49,6 @@ require_once(KT_LIB_DIR . '/help/help.inc.php');
49 49 require_once(KT_LIB_DIR . '/help/helpreplacement.inc.php');
50 50 require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
51 51  
52   -require_once('loginUtil.inc.php');
53 52  
54 53 class loginResetDispatcher extends KTDispatcher {
55 54  
... ... @@ -80,7 +79,7 @@ class loginResetDispatcher extends KTDispatcher {
80 79 $_REQUEST['errorMessage'] = join('. <br /> ', $_REQUEST['errorMessage']);
81 80 }
82 81  
83   - if(!loginUtil::check() && $_SESSION['userID'] != -2) { // bounce here, potentially.
  82 + if(!$this->check() && $_SESSION['userID'] != -2) { // bounce here, potentially.
84 83 // User is already logged in - get the redirect
85 84 $redirect = strip_tags(KTUtil::arrayGet($_REQUEST, 'redirect'));
86 85  
... ... @@ -169,7 +168,7 @@ class loginResetDispatcher extends KTDispatcher {
169 168 function do_login() {
170 169 $aExtra = array();
171 170  
172   - if(!loginUtil::check() && $_SESSION['userID'] != -2) { // bounce here, potentially.
  171 + if(!$this->check() && $_SESSION['userID'] != -2) { // bounce here, potentially.
173 172 // User is already logged in - get the redirect
174 173 $redirect = strip_tags(KTUtil::arrayGet($_REQUEST, 'redirect'));
175 174  
... ... @@ -210,7 +209,7 @@ class loginResetDispatcher extends KTDispatcher {
210 209 $oUser =& User::getByUsername($username);
211 210 if (PEAR::isError($oUser) || ($oUser === false)) {
212 211 if (is_a($oUser, 'ktentitynoobjects')) {
213   - loginUtil::handleUserDoesNotExist($username, $password, $aExtra);
  212 + $this->handleUserDoesNotExist($username, $password, $aExtra);
214 213 }
215 214 $this->simpleRedirectToMain(_kt('Login failed. Please check your username and password, and try again.'), $url, $queryParams);
216 215 exit(0);
... ... @@ -232,7 +231,7 @@ class loginResetDispatcher extends KTDispatcher {
232 231 exit(0);
233 232 }
234 233  
235   - $res = loginUtil::performLogin($oUser);
  234 + $res = $this->performLogin($oUser);
236 235  
237 236 if ($res) {
238 237 $this->simpleRedirectToMain($res->getMessage(), $url, $queryParams);
... ... @@ -240,6 +239,107 @@ class loginResetDispatcher extends KTDispatcher {
240 239 }
241 240 }
242 241  
  242 + /**
  243 + * Check if the user is already logged in or if anonymous login is enabled
  244 + *
  245 + * @return boolean false if the user is logged in
  246 + */
  247 + function check() {
  248 + $session = new Session();
  249 + $sessionStatus = $session->verify();
  250 +
  251 + if ($sessionStatus === true) { // the session is valid
  252 + if ($_SESSION['userID'] == -2 && $default->allowAnonymousLogin) {
  253 + // Anonymous user - we want to login
  254 + return true;
  255 + } else {
  256 + return false;
  257 + }
  258 + }
  259 + return true;
  260 + }
  261 +
  262 + /**
  263 + * Verify the user session
  264 + *
  265 + */
  266 + function do_providerVerify() {
  267 + $this->session = new Session();
  268 + $sessionStatus = $this->session->verify();
  269 + if ($sessionStatus !== true) { // the session is not valid
  270 + $this->redirectToMain();
  271 + }
  272 + $this->oUser =& User::get($_SESSION['userID']);
  273 + $oProvider =& KTAuthenticationUtil::getAuthenticationProviderForUser($this->oUser);
  274 + $oProvider->subDispatch($this);
  275 + exit(0);
  276 + }
  277 +
  278 + /**
  279 + * Log the user into the system
  280 + *
  281 + * @param unknown_type $oUser
  282 + * @return unknown
  283 + */
  284 + function performLogin(&$oUser) {
  285 + if (!is_a($oUser, 'User')) {
  286 + }
  287 +
  288 + $session = new Session();
  289 + $sessionID = $session->create($oUser);
  290 + if (PEAR::isError($sessionID)) {
  291 + return $sessionID;
  292 + }
  293 +
  294 + $redirect = strip_tags(KTUtil::arrayGet($_REQUEST, 'redirect'));
  295 +
  296 + // DEPRECATED initialise page-level authorisation array
  297 + $_SESSION["pageAccess"] = NULL;
  298 +
  299 + $cookietest = KTUtil::randomString();
  300 + setcookie("CookieTestCookie", $cookietest, 0);
  301 +
  302 + $this->redirectTo('checkCookie', array(
  303 + 'cookieVerify' => $cookietest,
  304 + 'redirect' => $redirect,
  305 + ));
  306 + exit(0);
  307 + }
  308 +
  309 + function handleUserDoesNotExist($username, $password, $aExtra = null) {
  310 + if (empty($aExtra)) {
  311 + $aExtra = array();
  312 + }
  313 +
  314 + // Check if the user has been deleted before allowing auto-signup
  315 + $delUser = User::checkDeletedUser($username);
  316 +
  317 + if($delUser){
  318 + return ;
  319 + }
  320 +
  321 + $oKTConfig = KTConfig::getSingleton();
  322 + $allow = $oKTConfig->get('session/allowAutoSignup', true);
  323 +
  324 + if($allow){
  325 + $res = KTAuthenticationUtil::autoSignup($username, $password, $aExtra);
  326 + if (empty($res)) {
  327 + return $res;
  328 + }
  329 + if (is_a($res, 'User')) {
  330 + $this->performLogin($res);
  331 + }
  332 + if (is_a($res, 'KTAuthenticationSource')) {
  333 + $_SESSION['autosignup'] = $aExtra;
  334 + $this->redirectTo('autoSignup', array(
  335 + 'source_id' => $res->getId(),
  336 + 'username' => $username,
  337 + ));
  338 + exit(0);
  339 + }
  340 + }
  341 + }
  342 +
243 343 function do_autoSignup() {
244 344 $oSource =& $this->oValidator->validateAuthenticationSource($_REQUEST['source_id']);
245 345 $oProvider =& KTAuthenticationUtil::getAuthenticationProviderForSource($oSource);
... ...
plugins/passwordResetPlugin/loginUtil.inc.php deleted
1   -<?php
2   -/**
3   - * $Id: $
4   - *
5   - * This page handles logging a user into the dms.
6   - * This page displays the login form, and performs the business logic login processing.
7   - *
8   - * KnowledgeTree Community Edition
9   - * Document Management Made Simple
10   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
11   - * Portions copyright The Jam Warehouse Software (Pty) Limited
12   - *
13   - * This program is free software; you can redistribute it and/or modify it under
14   - * the terms of the GNU General Public License version 3 as published by the
15   - * Free Software Foundation.
16   - *
17   - * This program is distributed in the hope that it will be useful, but WITHOUT
18   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20   - * details.
21   - *
22   - * You should have received a copy of the GNU General Public License
23   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
24   - *
25   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
26   - * California 94120-7775, or email info@knowledgetree.com.
27   - *
28   - * The interactive user interfaces in modified source and object code versions
29   - * of this program must display Appropriate Legal Notices, as required under
30   - * Section 5 of the GNU General Public License version 3.
31   - *
32   - * In accordance with Section 7(b) of the GNU General Public License version 3,
33   - * these Appropriate Legal Notices must retain the display of the "Powered by
34   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
35   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
36   - * must display the words "Powered by KnowledgeTree" and retain the original
37   - * copyright notice.
38   - * Contributor( s): ______________________________________
39   - */
40   -
41   -require_once(KT_LIB_DIR . '/session/Session.inc');
42   -
43   -class loginUtil
44   -{
45   - /**
46   - * Check if the user is already logged in or if anonymous login is enabled
47   - *
48   - * @return boolean false if the user is logged in
49   - */
50   - function check() {
51   - $session = new Session();
52   - $sessionStatus = $session->verify();
53   -
54   - if ($sessionStatus === true) { // the session is valid
55   - if ($_SESSION['userID'] == -2 && $default->allowAnonymousLogin) {
56   - // Anonymous user - we want to login
57   - return true;
58   - } else {
59   - return false;
60   - }
61   - }
62   - return true;
63   - }
64   -
65   - /**
66   - * Verify the user session
67   - *
68   - */
69   - function do_providerVerify() {
70   - $this->session = new Session();
71   - $sessionStatus = $this->session->verify();
72   - if ($sessionStatus !== true) { // the session is not valid
73   - $this->redirectToMain();
74   - }
75   - $this->oUser =& User::get($_SESSION['userID']);
76   - $oProvider =& KTAuthenticationUtil::getAuthenticationProviderForUser($this->oUser);
77   - $oProvider->subDispatch($this);
78   - exit(0);
79   - }
80   -
81   - /**
82   - * Log the user into the system
83   - *
84   - * @param unknown_type $oUser
85   - * @return unknown
86   - */
87   - function performLogin(&$oUser) {
88   - if (!is_a($oUser, 'User')) {
89   - }
90   -
91   - $session = new Session();
92   - $sessionID = $session->create($oUser);
93   - if (PEAR::isError($sessionID)) {
94   - return $sessionID;
95   - }
96   -
97   - $redirect = strip_tags(KTUtil::arrayGet($_REQUEST, 'redirect'));
98   -
99   - // DEPRECATED initialise page-level authorisation array
100   - $_SESSION["pageAccess"] = NULL;
101   -
102   - $cookietest = KTUtil::randomString();
103   - setcookie("CookieTestCookie", $cookietest, 0);
104   -
105   - $this->redirectTo('checkCookie', array(
106   - 'cookieVerify' => $cookietest,
107   - 'redirect' => $redirect,
108   - ));
109   - exit(0);
110   - }
111   -
112   - function handleUserDoesNotExist($username, $password, $aExtra = null) {
113   - if (empty($aExtra)) {
114   - $aExtra = array();
115   - }
116   -
117   - // Check if the user has been deleted before allowing auto-signup
118   - $delUser = User::checkDeletedUser($username);
119   -
120   - if($delUser){
121   - return ;
122   - }
123   -
124   - $oKTConfig = KTConfig::getSingleton();
125   - $allow = $oKTConfig->get('session/allowAutoSignup', true);
126   -
127   - if($allow){
128   - $res = KTAuthenticationUtil::autoSignup($username, $password, $aExtra);
129   - if (empty($res)) {
130   - return $res;
131   - }
132   - if (is_a($res, 'User')) {
133   - $this->performLogin($res);
134   - }
135   - if (is_a($res, 'KTAuthenticationSource')) {
136   - $_SESSION['autosignup'] = $aExtra;
137   - $this->redirectTo('autoSignup', array(
138   - 'source_id' => $res->getId(),
139   - 'username' => $username,
140   - ));
141   - exit(0);
142   - }
143   - }
144   - }
145   -}
146   -?>