XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Primary.class.php
1<?php
6
7if (!defined('XOOPS_ROOT_PATH')) {
8 die();
9}
10
12{
13 public function preFilter()
14 {
15 $root =& XCube_Root::getSingleton();
16 $this->mController->mSetupUser->add('User_Utils::setupUser');
17 $this->mController->_mNotifyRedirectToUser->add('User_Utils::convertUrlToUser');
18
19 $file = XOOPS_ROOT_PATH . '/modules/user/kernel/LegacypageFunctions.class.php';
20
21 $root->mDelegateManager->add('Legacypage.Userinfo.Access', 'User_LegacypageFunctions::userinfo', $file);
22 $root->mDelegateManager->add('Legacypage.Edituser.Access', 'User_LegacypageFunctions::edituser', $file);
23 $root->mDelegateManager->add('Legacypage.Register.Access', 'User_LegacypageFunctions::register', $file);
24 $root->mDelegateManager->add('Legacypage.User.Access', 'User_LegacypageFunctions::user', $file);
25 $root->mDelegateManager->add('Legacypage.Lostpass.Access', 'User_LegacypageFunctions::lostpass', $file);
26 $root->mDelegateManager->add('Site.CheckLogin', 'User_LegacypageFunctions::checkLogin', $file);
27 $root->mDelegateManager->add('Site.CheckLogin.Success', 'User_LegacypageFunctions::checkLoginSuccess', $file);
28 $root->mDelegateManager->add('Site.Logout', 'User_LegacypageFunctions::logout', $file);
29
30 $root->mDelegateManager->add('Legacypage.Misc.Access', 'User_LegacypageFunctions::misc', XCUBE_DELEGATE_PRIORITY_NORMAL - 5, $file);
31 }
32}
33
34/***
35 * @internal
36 * This static class has a static member function for login process. Because
37 * this process is always called, this class is always loaded. We may move this
38 * class to other file. This file is a preload and no good for normal class
39 * definition.
40 *
41 * @todo We may move this class to other file.
42 */
44{
45 public static function setupUser(&$principal, &$controller, &$context)
46 {
47 if (is_object($context->mXoopsUser)) {
48 return;
49 }
50
51 if (!empty($_SESSION['xoopsUserId'])) {
52 $memberHandler = xoops_gethandler('member');
53 $user =& $memberHandler->getUser($_SESSION['xoopsUserId']);
54 $context->mXoopsUser =& $user;
55 if (is_object($context->mXoopsUser)) {
56 $context->mXoopsUser->setGroups($_SESSION['xoopsUserGroups']);
57
58 $roles = [];
59 $roles[] = 'Site.RegisteredUser';
60 if ($context->mXoopsUser->isAdmin(-1)) {
61 $roles[] = 'Site.Administrator';
62 }
63 if (in_array(XOOPS_GROUP_ADMIN, $_SESSION['xoopsUserGroups'])) {
64 $roles[] = 'Site.Owner';
65 }
66
67 $identity = new Legacy_Identity($context->mXoopsUser);
68 $principal = new Legacy_GenericPrincipal($identity, $roles);
69 return;
70 } else {
71 $context->mXoopsUser = null;
72 $_SESSION = [];
73 }
74 }
75 $identity = new Legacy_AnonymousIdentity();
76 $principal = new Legacy_GenericPrincipal($identity, ['Site.GuestUser']);
77 }
78
79 public static function convertUrlToUser(&$url)
80 {
81 global $xoopsRequestUri;
82 if (!preg_match('/xoops_redirect=/', $url)) {
83 if (!strstr($url, '?')) {
84 $url .= '?xoops_redirect=' . urlencode($xoopsRequestUri);
85 } else {
86 $url .= '&amp;xoops_redirect=' . urlencode($xoopsRequestUri);
87 }
88 }
89 }
90
98 public static function encryptPassword($password)
99 {
100 $pwd = $password;
101 XCube_DelegateUtils::call('User.EncryptPassword', new XCube_Ref($pwd));
102 return $pwd;
103 }
104
113 public static function passwordVerify($password, $hash)
114 {
115 $result = false;
116 XCube_DelegateUtils::call('User.PasswordVerify', new XCube_Ref($result), $password, $hash);
117 return $result;
118 }
119
127 public static function passwordNeedsRehash($value)
128 {
129 $needs = false;
130 XCube_DelegateUtils::call('User.PasswordNeedsRehash', new XCube_Ref($needs), $value);
131 return $needs;
132 }
133
139 public static function checkUsersPassColumnLength()
140 {
141 $res = true;
142 if (!defined('XCUBE_CORE_USER_PASS_LEN_FIXED')) {
143 $res = false;
144 $root = XCube_Root::getSingleton();
145 $db = $root->mController->mDB;
146 $sql = 'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA="'.XOOPS_DB_NAME.'" AND TABLE_NAME="'.$db->prefix('users').'" AND COLUMN_NAME="pass"';
147 if ($res = $db->query($sql)) {
148 $type = $db->fetchRow($res);
149 if (preg_replace('/[^0-9]/', '', $type[0]) > 191) {
150 $sql = 'ALTER TABLE '.$db->prefix('users').' CHANGE `pass` `pass` VARCHAR(191) NOT NULL DEFAULT ""';
151 $res = $db->queryF($sql);
152 } else {
153 $res = true;
154 }
155 if ($res) {
156 define('XCUBE_CORE_USER_PASS_LEN_FIXED', true);
157 }
158 }
159 }
160 return $res;
161 }
162}
preFilter()
[Abstract] Executes the logic, when the controller executes preFilter().
static passwordVerify($password, $hash)
static passwordNeedsRehash($value)
static encryptPassword($password)
static checkUsersPassColumnLength()