dolibarr  13.0.2
Auth.class.php
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 <https://www.gnu.org/licenses/>.
17  */
18 
19 
23 class Auth
24 {
25  protected $db;
26 
27  private $login;
28  private $passwd;
29 
30  private $reponse;
31 
32  public $sqlQuery;
33 
40  public function __construct($db)
41  {
42  $this->db = $db;
43  $this->reponse(null);
44  }
45 
52  public function login($aLogin)
53  {
54  $this->login = $aLogin;
55  }
56 
63  public function passwd($aPasswd)
64  {
65  $this->passwd = $aPasswd;
66  }
67 
74  public function reponse($aReponse)
75  {
76  $this->reponse = $aReponse;
77  }
78 
86  public function verif($aLogin, $aPasswd)
87  {
88  global $conf, $langs;
89  global $dolibarr_main_authentication, $dolibarr_auto_user;
90 
91  $ret = -1;
92 
93  $login = '';
94 
95  $test = true;
96 
97  // Authentication mode
98  if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication = 'http,dolibarr';
99  // Authentication mode: forceuser
100  if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user = 'auto';
101  // Set authmode
102  $authmode = explode(',', $dolibarr_main_authentication);
103 
104  // No authentication mode
105  if (!count($authmode))
106  {
107  $langs->load('main');
108  dol_print_error('', $langs->trans("ErrorConfigParameterNotDefined", 'dolibarr_main_authentication'));
109  exit;
110  }
111 
112  $usertotest = $aLogin;
113  $passwordtotest = $aPasswd;
114  $entitytotest = $conf->entity;
115 
116  // Validation tests user / password
117  // If ok, the variable will be initialized login
118  // If error, we will put error message in session under the name dol_loginmesg
119  $goontestloop = false;
120  if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode)) $goontestloop = true;
121  if (isset($aLogin) || GETPOST('openid_mode', 'alpha', 1)) $goontestloop = true;
122 
123  if ($test && $goontestloop)
124  {
125  include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
126  $login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode);
127  if ($login)
128  {
129  $this->login($aLogin);
130  $this->passwd($aPasswd);
131  $ret = 0;
132  } else {
133  $ret = -1;
134  }
135  }
136 
137  return $ret;
138  }
139 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
login($aLogin)
Enter description here ...
Definition: Auth.class.php:52
Class ot manage authentication for pos module (cashdesk)
Definition: Auth.class.php:23
passwd($aPasswd)
Enter description here ...
Definition: Auth.class.php:63
$conf db
API class for accounts.
Definition: inc.php:54
reponse($aReponse)
Enter description here ...
Definition: Auth.class.php:74
print $_SERVER["PHP_SELF"]
Edit parameters.
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context= '')
Return a login if login/pass was successfull.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
verif($aLogin, $aPasswd)
Validate login/pass.
Definition: Auth.class.php:86
__construct($db)
Enter description here ...
Definition: Auth.class.php:40