dolibarr  7.0.0-beta
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 <http://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  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  }
133  else
134  {
135  $ret=-1;
136  }
137  }
138 
139  return $ret;
140  }
141 
142 }
143 
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
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
reponse($aReponse)
Enter description here ...
Definition: Auth.class.php:74
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode)
Return a login if login/pass was successfull.
verif($aLogin, $aPasswd)
Validate login/pass.
Definition: Auth.class.php:86
__construct($db)
Enter description here ...
Definition: Auth.class.php:40