XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
LegacypageFunctions.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12/***
13 * @internal
14 * This is static functions collection class for legacy pages access.
15 */
17{
18 public static $passwordNeedsRehash;
19 /***
20 * @internal
21 * The process for userinfo.php. This process doesn't execute anything
22 * directly. Forward to the controller of the user module.
23 */
24 public static function userinfo()
25 {
26 //
27 // Boot the action frame of the user module directly.
28 //
29 $root =& XCube_Root::getSingleton();
30 $root->mController->executeHeader();
31
32 $root->mController->setupModuleContext('user');
33 $root->mLanguageManager->loadModuleMessageCatalog('user');
34
35 require_once XOOPS_MODULE_PATH . '/user/class/ActionFrame.class.php';
36
37 $moduleRunner = new User_ActionFrame(false);
38 $moduleRunner->setActionName('UserInfo');
39
40 $root->mController->mExecute->add([&$moduleRunner, 'execute']);
41
42 $root->mController->execute();
43
44 $root->mController->executeView();
45 }
46
47 /***
48 * @internal
49 * The process for edituser.php. This process doesn't execute anything
50 * directly. Forward to the controller of the user module.
51 */
52 public static function edituser()
53 {
54 $actionName = 'EditUser';
55 switch (xoops_getrequest('op')) {
56 case 'avatarform':
57 case 'avatarupload':
58 $actionName = 'AvatarEdit';
59 break;
60
61 case 'avatarchoose':
62 $actionName = 'AvatarSelect';
63 break;
64 }
65
66 //
67 // Boot the action frame of the user module directly.
68 //
69 $root =& XCube_Root::getSingleton();
70 $root->mController->executeHeader();
71
72 $root->mController->setupModuleContext('user');
73 $root->mLanguageManager->loadModuleMessageCatalog('user');
74
75 require_once XOOPS_MODULE_PATH . '/user/class/ActionFrame.class.php';
76
77 $moduleRunner = new User_ActionFrame(false);
78 $moduleRunner->setActionName($actionName);
79
80 $root->mController->mExecute->add([&$moduleRunner, 'execute']);
81
82 $root->mController->execute();
83
84 $root->mController->executeView();
85 }
86
87 /***
88 * @internal
89 * The process for register.php. This process doesn't execute anything
90 * directly. Forward to the controller of the user module.
91 */
92 public static function register()
93 {
94 $root =& XCube_Root::getSingleton();
95 $xoopsUser =& $root->mContext->mXoopsUser;
96
97 if (is_object($xoopsUser)) {
98 $root->mController->executeForward(XOOPS_URL);
99 }
100
101 //
102 // Boot the action frame of the user module directly.
103 //
104 $root->mController->executeHeader();
105
106 $root->mController->setupModuleContext('user');
107 $root->mLanguageManager->loadModuleMessageCatalog('user');
108
109 require_once XOOPS_MODULE_PATH . '/user/class/ActionFrame.class.php';
110
111 $actionName = '';
112 $action = $root->mContext->mRequest->getRequest('action');
113 if (null != $action && 'UserRegister' == $action) {
114 $actionName = 'UserRegister';
115 } else {
116 $actionName = null != $action ? 'UserRegister_confirm' : 'UserRegister';
117 }
118
119 $moduleRunner = new User_ActionFrame(false);
120 $moduleRunner->setActionName($actionName);
121
122 $root->mController->mExecute->add([&$moduleRunner, 'execute']);
123
124 $root->mController->execute();
125
126 $root->mController->executeView();
127 }
128
129 /***
130 * @internal
131 * The process for lostpass.php. This process doesn't execute anything
132 * directly. If the current user is registered user, kick out to the top
133 * page. Else, forward to the lost-pass page.
134 */
135 public static function lostpass()
136 {
137 $root =& XCube_Root::getSingleton();
138 $xoopsUser =& $root->mContext->mXoopsUser;
139
140 if (is_object($xoopsUser)) {
141 $root->mController->executeForward(XOOPS_URL);
142 }
143
144 //
145 // Boot the action frame of the user module directly.
146 //
147 $root->mController->executeHeader();
148
149 $root->mController->setupModuleContext('user');
150 $root->mLanguageManager->loadModuleMessageCatalog('user');
151
152 require_once XOOPS_MODULE_PATH . '/user/class/ActionFrame.class.php';
153
154 $root =& XCube_Root::getSingleton();
155
156 $moduleRunner = new User_ActionFrame(false);
157 $moduleRunner->setActionName('LostPass');
158
159 $root->mController->mExecute->add([&$moduleRunner, 'execute']);
160
161 $root->mController->execute();
162
163 $root->mController->executeView();
164 }
165
166 /***
167 * @internal
168 * The process for user.php. This process doesn't execute anything directly.
169 * Forward to the controller of the user module.
170 */
171 public static function user()
172 {
173 $root =& XCube_Root::getSingleton();
174 $op = isset($_REQUEST['op']) ? trim(xoops_getrequest('op')) : 'main';
175 $xoopsUser =& $root->mContext->mXoopsUser;
176
177 $actionName = 'default';
178
179 switch ($op) {
180 case 'login':
181 $root->mController->checkLogin();
182 return;
183
184 case 'logout':
185 $root->mController->logout();
186 return;
187
188 case 'main':
189 if (is_object($xoopsUser)) {
190 $root->mController->executeForward(XOOPS_URL . '/userinfo.php?uid=' . $xoopsUser->get('uid'));
191 }
192 break;
193
194 case 'actv':
195 $actionName = 'UserActivate';
196 break;
197
198 case 'delete':
199 $actionName = 'UserDelete';
200 break;
201 }
202
203 //
204 // Boot the action frame of the user module directly.
205 //
206 $root =& XCube_Root::getSingleton();
207 $root->mController->executeHeader();
208
209 $root->mController->setupModuleContext('user');
210 $root->mLanguageManager->loadModuleMessageCatalog('user');
211
212 require_once XOOPS_MODULE_PATH . '/user/class/ActionFrame.class.php';
213
214 $moduleRunner = new User_ActionFrame(false);
215 $moduleRunner->setActionName($actionName);
216
217 $root->mController->mExecute->add([&$moduleRunner, 'execute']);
218
219 $root->mController->execute();
220
221 $root->mController->executeView();
222 }
223
224 public static function checkLogin(&$xoopsUser)
225 {
226 if (is_object($xoopsUser)) {
227 return;
228 }
229
230 $root = XCube_Root::getSingleton();
231 $root->mLanguageManager->loadModuleMessageCatalog('user');
232
233 $userHandler = xoops_getmodulehandler('users', 'user');
234
235 $criteria = new CriteriaCompo();
236 $criteria->add(new Criteria('uname', xoops_getrequest('uname')));
237 $userArr = $userHandler->getObjects($criteria);
238 if (1 != (is_countable($userArr) ? count($userArr) : 0)) {
239 return;
240 }
241
242 $pass = xoops_getrequest('pass');
243 $hash = $userArr[0]->get('pass');
244 if (! User_Utils::passwordVerify($pass, $hash)) {
245 return;
246 }
247
248 if (0 == $userArr[0]->get('level')) {
249 // TODO We should use message "_MD_USER_LANG_NOACTTPADM"
250 return;
251 }
252
253 $handler =& xoops_gethandler('user');
254 $user =& $handler->get($userArr[0]->get('uid'));
255
256 if (is_callable([$user, 'getNumGroups'])) { // Compatible for replaced handler.
257 if (0 == $user->getNumGroups()) {
258 return;
259 }
260 } else {
261 $groups = $user->getGroups();
262 if (0 == (is_countable($groups) ? count($groups) : 0)) {
263 return;
264 }
265 }
266
267 // auto re-hash
269 $user->set('pass', User_Utils::encryptPassword($pass), true);
270 if (!$handler->insert($user, true)) {
271 // set $passwordNeedsRehash
272 self::$passwordNeedsRehash = true;
273 }
274 }
275
276 $xoopsUser = $user;
277
278 //
279 // Regist to session
280 //
281 if (!isset($_SESSION)) {
282 $root->mSession->regenerate();
283 }
284 $_SESSION = [];
285 $_SESSION['xoopsUserId'] = $xoopsUser->get('uid');
286 $_SESSION['xoopsUserGroups'] = $xoopsUser->getGroups();
287 }
288
289 public static function checkLoginSuccess(&$xoopsUser)
290 {
291 if (is_object($xoopsUser)) {
292 $handler = xoops_gethandler('user');
293 $xoopsUser->set('last_login', time());
294
295 $handler->insert($xoopsUser);
296
297 if (self::$passwordNeedsRehash) {
298 $url = XOOPS_URL . '/edituser.php';
299 if (($redirect = xoops_getrequest('xoops_redirect')) && '/' === $redirect[0]) {
300 $url .= '?xoops_redirect=' . rawurlencode($redirect);
301 }
302 $root = XCube_Root::getSingleton();
303 $root->mController->executeRedirect($url, 5, _MD_USER_MESSAGE_REPASSWORD);
304 }
305 }
306 }
307
308 public static function logout(&$successFlag, $xoopsUser)
309 {
310 $root =& XCube_Root::getSingleton();
311 $xoopsConfig = $root->mContext->mXoopsConfig;
312
313 $root->mLanguageManager->loadModuleMessageCatalog('user');
314
315 // Reset session
316 $_SESSION = [];
317 $root->mSession->destroy(true);
318
319 // clear entry from online users table
320 if (is_object($xoopsUser)) {
321 $onlineHandler =& xoops_gethandler('online');
322 $onlineHandler->destroy($xoopsUser->get('uid'));
323 }
324
325 $successFlag = true;
326 }
327
328 public static function misc()
329 {
330 if ('online' !== xoops_getrequest('type')) {
331 return;
332 }
333
334 require_once XOOPS_MODULE_PATH . '/user/class/ActionFrame.class.php';
335
336 $root =& XCube_Root::getSingleton();
337 $root->mController->setupModuleContext('user');
338
339 $actionName = 'MiscOnline';
340
341 $moduleRunner = new User_ActionFrame(false);
342 $moduleRunner->setActionName($actionName);
343
344 $root->mController->mExecute->add([&$moduleRunner, 'execute']);
345
346 $root->mController->setDialogMode(true);
347
348 $root->mController->execute();
349
350 $root->mController->executeView();
351 }
352}
static passwordVerify($password, $hash)
static passwordNeedsRehash($value)
static encryptPassword($password)