XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
auth_provisionning.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
32 {
34 
41  function &getInstance(&$auth_instance)
42  {
43  static $provis_instance;
44  if (!isset($provis_instance)) {
45  $provis_instance = new XoopsAuthProvisionning($auth_instance);
46  }
47  return $provis_instance;
48  }
49 
53  function XoopsAuthProvisionning(&$auth_instance)
54  {
55  $this->_auth_instance =& $auth_instance;
56  $config_handler =& xoops_gethandler('config');
57  $config = $config_handler->getConfigsByCat(XOOPS_CONF_AUTH);
58  foreach ($config as $key => $val) {
59  $this->$key = $val;
60  }
61  $config_gen = $config_handler->getConfigsByCat(XOOPS_CONF);
62  $this->default_TZ = $config_gen['default_TZ'];
63  $this->theme_set = $config_gen['theme_set'];
64  $this->com_mode = $config_gen['com_mode'];
65  $this->com_order = $config_gen['com_order'];
66  }
67 
73  function getXoopsUser($uname)
74  {
75  $member_handler =& xoops_gethandler('member');
76  $criteria = new Criteria('uname', $uname);
77  $getuser = $member_handler->getUsers($criteria);
78  if (count($getuser) == 1) {
79  return $getuser[0];
80  } else {
81  return false;
82  }
83  }
84 
90  function sync($datas, $uname, $pwd = null)
91  {
92  $xoopsUser = $this->getXoopsUser($uname);
93  if (!$xoopsUser) { // Xoops User Database not exists
94  if ($this->ldap_provisionning) {
95  $xoopsUser = $this->add($datas, $uname, $pwd);
96  } else {
97  $this->_auth_instance->setErrors(0, sprintf(_AUTH_LDAP_XOOPS_USER_NOTFOUND, $uname));
98  }
99  } else { // Xoops User Database exists
100  if ($this->ldap_provisionning && $this->ldap_provisionning_upd) {
101  $xoopsUser = $this->change($xoopsUser, $datas, $uname, $pwd);
102  }
103  }
104  return $xoopsUser;
105  }
106 
112  function add($datas, $uname, $pwd = null)
113  {
114  $ret = false;
115  $member_handler =& xoops_gethandler('member');
116  // Create XOOPS Database User
117  $newuser = $member_handler->createUser();
118  $newuser->setVar('uname', $uname);
119  $newuser->setVar('pass', md5(stripslashes($pwd)));
120  $newuser->setVar('rank', 0);
121  $newuser->setVar('level', 1);
122  $newuser->setVar('timezone_offset', $this->default_TZ);
123  $newuser->setVar('theme', $this->theme_set);
124  $newuser->setVar('umode', $this->com_mode);
125  $newuser->setVar('uorder', $this->com_order);
126  $tab_mapping = explode('|', $this->ldap_field_mapping);
127  foreach ($tab_mapping as $mapping) {
128  $fields = explode('=', trim($mapping));
129  if ($fields[0] && $fields[1])
130  $newuser->setVar(trim($fields[0]), utf8_decode($datas[trim($fields[1])][0]));
131  }
132  if ($member_handler->insertUser($newuser)) {
133  foreach($this->ldap_provisionning_group as $groupid) {
134  $member_handler->addUserToGroup($groupid, $newuser->getVar('uid'));
135  }
136  $newuser->unsetNew();
137  return $newuser;
138  } else {
139  redirect_header(XOOPS_URL . '/user.php', 5, $newuser->getHtmlErrors());
140  }
141  return $ret;
142  }
143 
149  function change(&$xoopsUser, $datas, $uname, $pwd = null)
150  {
151  $ret = false;
152  $member_handler =& xoops_gethandler('member');
153  $xoopsUser->setVar('pass', md5(stripslashes($pwd)));
154  $tab_mapping = explode('|', $this->ldap_field_mapping);
155  foreach ($tab_mapping as $mapping) {
156  $fields = explode('=', trim($mapping));
157  if ($fields[0] && $fields[1]) {
158  $xoopsUser->setVar(trim($fields[0]), utf8_decode($datas[trim($fields[1])][0]));
159  }
160  }
161  if ($member_handler->insertUser($xoopsUser)) {
162  return $xoopsUser;
163  } else {
164  redirect_header(XOOPS_URL . '/user.php', 5, $xoopsUser->getHtmlErrors());
165  }
166  return $ret;
167  }
168 
174  function delete()
175  {
176  }
177 
183  function suspend()
184  {
185  }
186 
192  function restore()
193  {
194  }
195 
201  function resetpwd()
202  {
203  }
204 } // end class
205 
206 ?>