PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/cashdesk/class/Auth.class.php

https://github.com/asterix14/dolibarr
PHP | 143 lines | 65 code | 21 blank | 57 comment | 13 complexity | 171538d779dac438b5268b35d7552db2 MD5 | raw file
Possible License(s): LGPL-2.0
  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 2 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 Auth($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) && empty($conf->login_method_modules))
  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. $login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
  108. if ($login)
  109. {
  110. $this->login($aLogin);
  111. $this->passwd($aPasswd);
  112. $ret=0;
  113. }
  114. else
  115. {
  116. $ret=-1;
  117. }
  118. }
  119. return $ret;
  120. }
  121. }
  122. ?>