XOOPS  2.6.0
Provisioning.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Auth;
13 
15 
30 {
34  protected $auth_instance;
35 
40 
45 
50 
55 
63  public static function getInstance(AuthAbstract $auth_instance)
64  {
65  static $provis_instance;
66  if (!isset($provis_instance)) {
67  $provis_instance = new self($auth_instance);
68  }
69 
70  return $provis_instance;
71  }
72 
79  {
81  $this->auth_instance = $auth_instance;
82  $configs = $xoops->getConfigs();
83  foreach ($configs as $key => $val) {
84  $this->$key = $val;
85  }
86  }
87 
95  public function getXoopsUser($uname)
96  {
98  $member_handler = $xoops->getHandlerMember();
99  $criteria = new Criteria('uname', $uname);
100  $getuser = $member_handler->getUsers($criteria);
101  if (count($getuser) == 1) {
102  return $getuser[0];
103  } else {
104  return false;
105  }
106  }
107 
117  public function sync($data, $uname, $pwd = null)
118  {
119  $xoopsUser = $this->getXoopsUser($uname);
120  if (!$xoopsUser) { // Xoops User Database not exists
121  if ($this->ldap_provisioning) {
122  $xoopsUser = $this->add($data, $uname, $pwd);
123  } else {
124  $this->auth_instance->setErrors(0, sprintf(
126  $uname
127  ));
128  }
129  } else { // Xoops User Database exists
130  if ($this->ldap_provisioning && $this->ldap_provisioning_upd) {
131  $xoopsUser = $this->change($xoopsUser, $data, $uname, $pwd);
132  }
133  }
134 
135  return $xoopsUser;
136  }
137 
146  protected function setVarsMapping($object, $data)
147  {
148  $tab_mapping = explode('|', $this->ldap_field_mapping);
149  foreach ($tab_mapping as $mapping) {
150  $fields = explode('=', trim($mapping));
151  if (isset($fields[0]) and ($field0 = trim($fields[0]))) {
152  $str = '';
153  if (isset($fields[1]) and ($field1 = trim($fields[1]))) {
154  if (!empty($data[$field1][0])) {
155  $str = $data[$field1][0];
156  }
157  }
158  $object->setVar($field0, $str);
159  }
160  }
161  }
162 
172  public function add($data, $uname, $pwd = null)
173  {
175  $ret = false;
176  $member_handler = $xoops->getHandlerMember();
177  // Create XOOPS Database User
178  $newuser = $member_handler->createUser();
179  $newuser->setVar('uname', $uname);
180  $newuser->setVar('pass', password_hash(stripslashes($pwd), PASSWORD_DEFAULT));
181  $newuser->setVar('rank', 0);
182  $newuser->setVar('level', 1);
183  $newuser->setVar('timezone_offset', $xoops->getConfig('default_TZ'));
184  $newuser->setVar('theme', $xoops->getConfig('theme_set'));
185  //$newuser->setVar('umode', $xoops->getConfig('com_mode'));
186  //$newuser->setVar('uorder', $xoops->getConfig('com_order'));
187  $newuser->setVar('user_regdate', time());
188  $this->setVarsMapping($newuser, $data);
189 
190  if ($member_handler->insertUser($newuser)) {
191  foreach ($this->ldap_provisioning_group as $groupid) {
192  $member_handler->addUserToGroup($groupid, $newuser->getVar('uid'));
193  }
194  $newuser->unsetNew();
195 
196  return $newuser;
197  } else {
198  $xoops->redirect(\XoopsBaseConfig::get('url') . '/user.php', 5, $newuser->getHtmlErrors());
199  }
200 
201  return $ret;
202  }
203 
214  public function change(\XoopsUser $xoopsUser, $data, $uname, $pwd = null)
215  {
217  $ret = false;
218  $member_handler = $xoops->getHandlerMember();
219  $xoopsUser->setVar('pass', password_hash(stripslashes($pwd), PASSWORD_DEFAULT));
220  $this->setVarsMapping($xoopsUser, $data);
221 
222  if ($member_handler->insertUser($xoopsUser)) {
223  return $xoopsUser;
224  } else {
225  $xoops->redirect(\XoopsBaseConfig::get('url') . '/user.php', 5, $xoopsUser->getHtmlErrors());
226  }
227 
228  return $ret;
229  }
230 
236  public function delete()
237  {
238  }
239 
245  public function suspend()
246  {
247  }
248 
254  public function restore()
255  {
256  }
257 
263  public function resetpwd()
264  {
265  }
266 }
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
static getInstance()
Definition: Xoops.php:160
change(\XoopsUser $xoopsUser, $data, $uname, $pwd=null)
$xoops
Definition: admin.php:25
$getuser
Definition: lostpass.php:41
global $xoopsUser
Definition: config.php:132
const EF_CORRESPONDING_USER_NOT_FOUND_IN_DATABASE
Definition: en_US.php:230
add($data, $uname, $pwd=null)
static get($name)
setVarsMapping($object, $data)
$configs
Definition: config.php:27
$uname
Definition: checklogin.php:37
$criteria
static getInstance(AuthAbstract $auth_instance)
setVar($key, $value, $not_gpc=false)
__construct(AuthAbstract $auth_instance)
sync($data, $uname, $pwd=null)