Auth.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3. * Copyright (C) 2008-2011 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * Class ot manage authentication for pos module (cashdesk)
  20. */
  21. class Auth
  22. {
  23. var $db;
  24. var $login;
  25. var $passwd;
  26. var $reponse;
  27. var $sqlQuery;
  28. /**
  29. * Enter description here ...
  30. *
  31. * @param DoliDB $db Database handler
  32. * @return void
  33. */
  34. function __construct($db)
  35. {
  36. $this->db = $db;
  37. $this->reponse(null);
  38. }
  39. /**
  40. * Enter description here ...
  41. *
  42. * @param string $aLogin Login
  43. * @return void
  44. */
  45. function login($aLogin)
  46. {
  47. $this->login = $aLogin;
  48. }
  49. /**
  50. * Enter description here ...
  51. *
  52. * @param string $aPasswd Password
  53. * @return void
  54. */
  55. function passwd($aPasswd)
  56. {
  57. $this->passwd = $aPasswd;
  58. }
  59. /**
  60. * Enter description here ...
  61. *
  62. * @param string $aReponse Response
  63. * @return void
  64. */
  65. function reponse($aReponse)
  66. {
  67. $this->reponse = $aReponse;
  68. }
  69. /**
  70. * Validate login/pass
  71. *
  72. * @param string $aLogin Login
  73. * @param string $aPasswd Password
  74. * @return int 0 or 1
  75. */
  76. function verif($aLogin, $aPasswd)
  77. {
  78. global $conf,$langs;
  79. global $dolibarr_main_authentication,$dolibarr_auto_user;
  80. $ret=-1;
  81. $login='';
  82. $test=true;
  83. // Authentication mode
  84. if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
  85. // Authentication mode: forceuser
  86. if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
  87. // Set authmode
  88. $authmode=explode(',',$dolibarr_main_authentication);
  89. // No authentication mode
  90. if (! count($authmode))
  91. {
  92. $langs->load('main');
  93. dol_print_error('',$langs->trans("ErrorConfigParameterNotDefined",'dolibarr_main_authentication'));
  94. exit;
  95. }
  96. $usertotest=$aLogin;
  97. $passwordtotest=$aPasswd;
  98. $entitytotest=$conf->entity;
  99. // Validation tests user / password
  100. // If ok, the variable will be initialized login
  101. // If error, we will put error message in session under the name dol_loginmesg
  102. $goontestloop=false;
  103. if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
  104. if (isset($aLogin) || GETPOST('openid_mode','alpha',1)) $goontestloop=true;
  105. if ($test && $goontestloop)
  106. {
  107. include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  108. $login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
  109. if ($login)
  110. {
  111. $this->login($aLogin);
  112. $this->passwd($aPasswd);
  113. $ret=0;
  114. }
  115. else
  116. {
  117. $ret=-1;
  118. }
  119. }
  120. return $ret;
  121. }
  122. }