PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/passwordResetPlugin/loginUtil.inc.php

https://github.com/sfsergey/knowledgetree
PHP | 146 lines | 75 code | 15 blank | 56 comment | 14 complexity | b3cd140b66aa728c0ae724b1f1f53635 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, GPL-3.0
  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. require_once(KT_LIB_DIR . '/session/Session.inc');
  41. class loginUtil
  42. {
  43. /**
  44. * Check if the user is already logged in or if anonymous login is enabled
  45. *
  46. * @return boolean false if the user is logged in
  47. */
  48. function check() {
  49. $session = new Session();
  50. $sessionStatus = $session->verify();
  51. if ($sessionStatus === true) { // the session is valid
  52. if ($_SESSION['userID'] == -2 && $default->allowAnonymousLogin) {
  53. // Anonymous user - we want to login
  54. return true;
  55. } else {
  56. return false;
  57. }
  58. }
  59. return true;
  60. }
  61. /**
  62. * Verify the user session
  63. *
  64. */
  65. function do_providerVerify() {
  66. $this->session = new Session();
  67. $sessionStatus = $this->session->verify();
  68. if ($sessionStatus !== true) { // the session is not valid
  69. $this->redirectToMain();
  70. }
  71. $this->oUser =& User::get($_SESSION['userID']);
  72. $oProvider =& KTAuthenticationUtil::getAuthenticationProviderForUser($this->oUser);
  73. $oProvider->subDispatch($this);
  74. exit(0);
  75. }
  76. /**
  77. * Log the user into the system
  78. *
  79. * @param unknown_type $oUser
  80. * @return unknown
  81. */
  82. function performLogin(&$oUser) {
  83. if (!is_a($oUser, 'User')) {
  84. }
  85. $session = new Session();
  86. $sessionID = $session->create($oUser);
  87. if (PEAR::isError($sessionID)) {
  88. return $sessionID;
  89. }
  90. $redirect = strip_tags(KTUtil::arrayGet($_REQUEST, 'redirect'));
  91. // DEPRECATED initialise page-level authorisation array
  92. $_SESSION["pageAccess"] = NULL;
  93. $cookietest = KTUtil::randomString();
  94. setcookie("CookieTestCookie", $cookietest, 0);
  95. $this->redirectTo('checkCookie', array(
  96. 'cookieVerify' => $cookietest,
  97. 'redirect' => $redirect,
  98. ));
  99. exit(0);
  100. }
  101. function handleUserDoesNotExist($username, $password, $aExtra = null) {
  102. if (empty($aExtra)) {
  103. $aExtra = array();
  104. }
  105. // Check if the user has been deleted before allowing auto-signup
  106. $delUser = User::checkDeletedUser($username);
  107. if($delUser){
  108. return ;
  109. }
  110. $oKTConfig = KTConfig::getSingleton();
  111. $allow = $oKTConfig->get('session/allowAutoSignup', true);
  112. if($allow){
  113. $res = KTAuthenticationUtil::autoSignup($username, $password, $aExtra);
  114. if (empty($res)) {
  115. return $res;
  116. }
  117. if (is_a($res, 'User')) {
  118. $this->performLogin($res);
  119. }
  120. if (is_a($res, 'KTAuthenticationSource')) {
  121. $_SESSION['autosignup'] = $aExtra;
  122. $this->redirectTo('autoSignup', array(
  123. 'source_id' => $res->getId(),
  124. 'username' => $username,
  125. ));
  126. exit(0);
  127. }
  128. }
  129. }
  130. }
  131. ?>