Commit a553a89e746cd3423d3e768adcd8b6499cf33fea

Authored by jjordaan
2 parents 069eec81 3013fe57

Merge branch 'master' of git@github.com:ktgit/knowledgetree

lib/session/Session.inc
... ... @@ -152,7 +152,8 @@ class Session {
152 152 */
153 153 function removeStaleSessions($iUserId = null) {
154 154 global $default;
155   - $time = time() - $default->sessionTimeout;
  155 + $sessionTimeout = $default->sessionTimeout;
  156 + $time = time() - $sessionTimeout;
156 157  
157 158 // for web service sessions, we will expire after a month.
158 159 $monthPeriod = 30 * 24 * 60 * 60;
... ... @@ -172,7 +173,7 @@ class Session {
172 173 $mintime = formatDateTime($time);
173 174 $mintime2 = formatDateTime($wsTimeout);
174 175 $aQuery = array(
175   - sprintf("SELECT id, lastused, apptype FROM %s WHERE (user_id = $iUserId OR $iUserId = 0) AND ( (lastused <= '$mintime' and apptype = 'webapp') or (lastused <= '$mintime2' and apptype !='webapp') )", $sTable)
  176 + sprintf("SELECT id, user_id, lastused, apptype FROM %s WHERE (user_id = $iUserId OR $iUserId = 0) AND ( (lastused <= '$mintime' and apptype = 'webapp') or (lastused <= '$mintime2' and apptype !='webapp') )", $sTable)
176 177 );
177 178  
178 179 $aSessions = DBUtil::getResultArray($aQuery);
... ... @@ -182,12 +183,15 @@ class Session {
182 183  
183 184 foreach ($aSessions as $aSessionData) {
184 185 $iId = $aSessionData['id'];
  186 + $user_id = $aSessionData['user_id'];
  187 + $app_type = $aSessionData['apptype'];
185 188 $dLastUsed = $aSessionData['lastused'];
186 189 $iTime = strtotime($dLastUsed);
187 190  
188   - $iTime = $iTime + ($aSessionData['apptype'] != 'webapp')?$monthPeriod:$default->sessionTimeout;
  191 + $timeoutPeriod = ($app_type != 'webapp') ? $monthPeriod : $sessionTimeout;
  192 + $iTime = $iTime + (int)$timeoutPeriod;
189 193 $aParams = array(
190   - 'userid' => $iUserId,
  194 + 'userid' => $user_id,
191 195 'datetime' => formatDateTime($iTime),
192 196 'actionnamespace' => 'ktcore.user_history.timeout',
193 197 'comments' => 'Session timed out',
... ...
lib/users/User.inc
... ... @@ -447,6 +447,12 @@ class User extends KTEntity {
447 447 ), array('multi' => true));
448 448 }
449 449  
  450 + function getByLastLoginNever() {
  451 + $aOptions['orderby'] = 'name';
  452 + $sWhereClause = 'last_login is null';
  453 + return KTEntityUtil::getList2('User', $sWhereClause, $aOptions);
  454 + }
  455 +
450 456 function getByLastLoginAfter($dDateTime) {
451 457 return KTEntityUtil::getByDict('User', array(
452 458 'last_login' => array('type' => 'after', 'value' => $dDateTime),
... ...
plugins/ktcore/admin/documentFieldsv2.php
... ... @@ -402,9 +402,12 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher {
402 402 $data = $res['results'];
403 403 $errors = $res['errors'];
404 404 $extra_errors = array();
  405 +
  406 + // check that the fieldset name either hasn't changed, or doesn't exist.
405 407 if ($data['name'] != $this->oFieldset->getName()) {
406 408 $oOldFieldset = KTFieldset::getByName($data['name']);
407   - if (!PEAR::isError($oOldFieldset)) {
  409 + // If the fieldset exists throw an error. Mysql doesn't distinguish between Ž and e so check the names are different in php.
  410 + if (!PEAR::isError($oOldFieldset) && $oOldFieldset->getName() == $data['name']) {
408 411 $extra_errors['name'][] = _kt("A fieldset with that name already exists.");
409 412 }
410 413 }
... ...
plugins/passwordResetPlugin/loginResetDispatcher.php
... ... @@ -49,7 +49,6 @@ require_once(KT_LIB_DIR . &#39;/help/help.inc.php&#39;);
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   -?>