1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: |
|
30: | class XoopsAuthProvisionning
|
31: | {
|
32: | protected $_auth_instance;
|
33: |
|
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: |
|
41: | public static function getInstance(XoopsAuth $auth_instance = null)
|
42: | {
|
43: | static $provis_instance;
|
44: | if (!isset($provis_instance)) {
|
45: | $provis_instance = new XoopsAuthProvisionning($auth_instance);
|
46: | }
|
47: |
|
48: | return $provis_instance;
|
49: | }
|
50: |
|
51: | |
52: | |
53: | |
54: |
|
55: | public function __construct(XoopsAuth $auth_instance = null)
|
56: | {
|
57: | $this->_auth_instance = $auth_instance;
|
58: |
|
59: | $config_handler = xoops_getHandler('config');
|
60: | $config = $config_handler->getConfigsByCat(XOOPS_CONF_AUTH);
|
61: | foreach ($config as $key => $val) {
|
62: | $this->$key = $val;
|
63: | }
|
64: | $config_gen = $config_handler->getConfigsByCat(XOOPS_CONF);
|
65: | $this->default_TZ = $config_gen['default_TZ'];
|
66: | $this->theme_set = $config_gen['theme_set'];
|
67: | $this->com_mode = $config_gen['com_mode'];
|
68: | $this->com_order = $config_gen['com_order'];
|
69: | }
|
70: |
|
71: | |
72: | |
73: | |
74: | |
75: | |
76: |
|
77: | public function getXoopsUser($uname)
|
78: | {
|
79: |
|
80: | $member_handler = xoops_getHandler('member');
|
81: | $criteria = new Criteria('uname', $uname);
|
82: | $getuser = $member_handler->getUsers($criteria);
|
83: | if (count($getuser) == 1) {
|
84: | return $getuser[0];
|
85: | } else {
|
86: | return false;
|
87: | }
|
88: | }
|
89: |
|
90: | |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: |
|
98: | public function sync($datas, $uname, $pwd = null)
|
99: | {
|
100: | $xoopsUser = $this->getXoopsUser($uname);
|
101: | if (!$xoopsUser) {
|
102: | if ($this->ldap_provisionning) {
|
103: | $xoopsUser = $this->add($datas, $uname, $pwd);
|
104: | } else {
|
105: | $this->_auth_instance->setErrors(0, sprintf(_AUTH_LDAP_XOOPS_USER_NOTFOUND, $uname));
|
106: | }
|
107: | } else {
|
108: | if ($this->ldap_provisionning && $this->ldap_provisionning_upd) {
|
109: | $xoopsUser = $this->change($xoopsUser, $datas, $uname, $pwd);
|
110: | }
|
111: | }
|
112: |
|
113: | return $xoopsUser;
|
114: | }
|
115: |
|
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: |
|
124: | public function add($datas, $uname, $pwd = null)
|
125: | {
|
126: | $ret = false;
|
127: |
|
128: | $member_handler = xoops_getHandler('member');
|
129: |
|
130: | $newuser = $member_handler->createUser();
|
131: | $newuser->setVar('uname', $uname);
|
132: | $newuser->setVar('pass', password_hash(stripslashes($pwd), PASSWORD_DEFAULT));
|
133: | $newuser->setVar('rank', 0);
|
134: | $newuser->setVar('level', 1);
|
135: | $newuser->setVar('timezone_offset', $this->default_TZ);
|
136: | $newuser->setVar('theme', $this->theme_set);
|
137: | $newuser->setVar('umode', $this->com_mode);
|
138: | $newuser->setVar('uorder', $this->com_order);
|
139: | $tab_mapping = explode('|', $this->ldap_field_mapping);
|
140: | foreach ($tab_mapping as $mapping) {
|
141: | $fields = explode('=', trim($mapping));
|
142: | if ($fields[0] && $fields[1]) {
|
143: | $newuser->setVar(trim($fields[0]), xoops_utf8_decode($datas[trim($fields[1])][0]));
|
144: | }
|
145: | }
|
146: | if ($member_handler->insertUser($newuser)) {
|
147: | foreach ($this->ldap_provisionning_group as $groupid) {
|
148: | $member_handler->addUserToGroup($groupid, $newuser->getVar('uid'));
|
149: | }
|
150: | $newuser->unsetNew();
|
151: |
|
152: | return $newuser;
|
153: | } else {
|
154: | redirect_header(XOOPS_URL . '/user.php', 5, $newuser->getHtmlErrors());
|
155: | }
|
156: |
|
157: | return $ret;
|
158: | }
|
159: |
|
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | |
168: |
|
169: | public function change(&$xoopsUser, $datas, $uname, $pwd = null)
|
170: | {
|
171: | $ret = false;
|
172: |
|
173: | $member_handler = xoops_getHandler('member');
|
174: | $xoopsUser->setVar('pass', password_hash(stripcslashes($pwd), PASSWORD_DEFAULT));
|
175: | $tab_mapping = explode('|', $this->ldap_field_mapping);
|
176: | foreach ($tab_mapping as $mapping) {
|
177: | $fields = explode('=', trim($mapping));
|
178: | if ($fields[0] && $fields[1]) {
|
179: | $xoopsUser->setVar(trim($fields[0]), xoops_utf8_decode($datas[trim($fields[1])][0]));
|
180: | }
|
181: | }
|
182: | if ($member_handler->insertUser($xoopsUser)) {
|
183: | return $xoopsUser;
|
184: | } else {
|
185: | redirect_header(XOOPS_URL . '/user.php', 5, $xoopsUser->getHtmlErrors());
|
186: | }
|
187: |
|
188: | return $ret;
|
189: | }
|
190: |
|
191: | |
192: | |
193: | |
194: | |
195: |
|
196: | public function delete()
|
197: | {
|
198: | }
|
199: |
|
200: | |
201: | |
202: | |
203: | |
204: |
|
205: | public function suspend()
|
206: | {
|
207: | }
|
208: |
|
209: | |
210: | |
211: | |
212: | |
213: |
|
214: | public function restore()
|
215: | {
|
216: | }
|
217: |
|
218: | |
219: | |
220: | |
221: | |
222: |
|
223: | public function resetpwd()
|
224: | {
|
225: | }
|
226: | }
|
227: |
|
228: | |