Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezuserloginhandler.php
Go to the documentation of this file.
1 <?php
18 class eZUserLoginHandler
19 {
20 const AVAILABLE_ARRAY = 'eZLoginHandlerAvailbleArray'; // stores untested login handlers for login
21 const STEP = 'eZLoginHandlerStep';
22 const USER_INFO = 'eZLoginHandlerUserInfo';
23 const LAST_CHECK_REDIRECT = 'eZLoginHandlerLastCheckRedirect';
24 const FORCE_LOGIN = 'eZLoginHandlerForceLogin';
25 const LAST_HANDLER_NAME = 'eZLoginHandlerLastHandlerName';
26
27 const STEP_PRE_CHECK_USER_INFO = 0;
28 const STEP_PRE_COLLECT_USER_INFO = 1;
29 const STEP_POST_COLLECT_USER_INFO = 2;
30 const STEP_CHECK_USER = 3;
31 const STEP_LOGIN_USER = 4;
32
37 static function sessionCleanup()
38 {
39 $http = eZHTTPTool::instance();
40
41 $valueList = array( self::AVAILABLE_ARRAY,
42 self::STEP,
43 self::USER_INFO,
44 self::LAST_CHECK_REDIRECT,
45 self::FORCE_LOGIN );
46
47 foreach ( $valueList as $value )
48 {
49 if ( $http->hasSessionVariable( $value ) )
50 {
51 $http->removeSessionVariable( $value );
52 }
53 }
54
55 $ini = eZINI::instance();
56 $handlerList = array( 'standard' );
57 if ( $ini->hasVariable( 'UserSettings', 'LoginHandler' ) )
58 {
59 $handlerList = $ini->variable( 'UserSettings', 'LoginHandler' );
60 }
61
62 foreach( $handlerList as $handler )
63 {
64 $loginHandler = eZUserLoginHandler::instance( $handler );
65 if ( $loginHandler )
66 {
67 $loginHandler->sessionCleanup();
68 }
69 }
70 }
71
80 static function instance( $protocol = "standard" )
81 {
82 $triedFiles = array();
83 if ( $protocol == "standard" )
84 {
85 $impl = new eZUser( 0 );
86 return $impl;
87 }
88 else
89 {
90 $ezuserFile = 'kernel/classes/datatypes/ezuser/ez' . strtolower( $protocol ) . 'user.php';
91 $triedFiles[] = $ezuserFile;
92 if ( file_exists( $ezuserFile ) )
93 {
94 include_once( $ezuserFile );
95 $className = 'eZ' . $protocol . 'User';
96 $impl = new $className();
97 return $impl;
98 }
99 else // check in extensions
100 {
101 $ini = eZINI::instance();
102 $extensionDirectories = $ini->variable( 'UserSettings', 'ExtensionDirectory' );
103 $directoryList = eZExtension::expandedPathList( $extensionDirectories, 'login_handler' );
104
105 foreach( $directoryList as $directory )
106 {
107 $userFile = $directory . '/ez' . strtolower( $protocol ) . 'user.php';
108 $triedFiles[] = $userFile;
109
110 if ( file_exists( $userFile ) )
111 {
112 include_once( $userFile );
113 $className = 'eZ' . $protocol . 'User';
114 $impl = new $className();
115 return $impl;
116 }
117 }
118 }
119 }
120 // if no one appropriate instance was found
121 eZDebug::writeWarning( "Unable to find user login handler '$protocol', searched for these files: " . implode( ', ', $triedFiles ), __METHOD__ );
122 $impl = null;
123 return $impl;
124 }
125
135 public static function preCheck( array &$siteBasics, eZURI $uri )
136 {
137 if ( !$siteBasics['user-object-required'] )
138 {
139 return null;
140 }
141
142 $ini = eZINI::instance();
143 $requireUserLogin = ( $ini->variable( 'SiteAccessSettings', 'RequireUserLogin' ) == 'true' );
144 $forceLogin = false;
145 if ( eZSession::hasStarted() )
146 {
147 $http = eZHTTPTool::instance();
148 $forceLogin = $http->hasSessionVariable( self::FORCE_LOGIN );
149 }
150 if ( !$requireUserLogin && !$forceLogin )
151 {
152 return null;
153 }
154 return self::checkUser( $siteBasics, $uri );
155 }
156
169 static function checkUser( &$siteBasics, &$url )
170 {
171 $http = eZHTTPTool::instance();
172
173 if ( !$http->hasSessionVariable( self::STEP ) )
174 {
175 $http->setSessionVariable( self::STEP, self::STEP_PRE_CHECK_USER_INFO );
176 }
177
178 $loginStep =& $http->sessionVariable( self::STEP );
179
180 if ( $http->hasSessionVariable( self::FORCE_LOGIN ) &&
181 $loginStep < self::STEP_PRE_COLLECT_USER_INFO )
182 {
183 $loginStep = self::STEP_PRE_COLLECT_USER_INFO;
184 }
185
186 switch( $loginStep )
187 {
188 case self::STEP_PRE_CHECK_USER_INFO:
189 {
190 $ini = eZINI::instance();
191 $handlerList = array( 'standard' );
192 if ( $ini->hasVariable( 'UserSettings', 'LoginHandler' ) )
193 {
194 $handlerList = $ini->variable( 'UserSettings', 'LoginHandler' );
195 }
196
197 if ( $http->hasSessionVariable( self::LAST_HANDLER_NAME ) )
198 {
199 $http->removeSessionVariable( self::LAST_HANDLER_NAME );
200 }
201
202 foreach( $handlerList as $handler )
203 {
204 $userObject = eZUserLoginHandler::instance( $handler );
205 if ( $userObject )
206 {
207 $check = $userObject->checkUser( $siteBasics, $url );
208 if ( $check === null ) // No login needed.
209 {
210 eZUserLoginHandler::sessionCleanup();
211 return null;
212 }
213 $http->setSessionVariable( self::LAST_CHECK_REDIRECT, $check );
214 $http->setSessionVariable( self::LAST_HANDLER_NAME, $handler );
215 }
216 }
217
218 $http->setSessionVariable( self::STEP, self::STEP_PRE_COLLECT_USER_INFO );
219 return eZUserLoginHandler::checkUser( $siteBasics, $url );
220 } break;
221
222 case self::STEP_PRE_COLLECT_USER_INFO:
223 {
224 $http->setSessionVariable( self::STEP, self::STEP_POST_COLLECT_USER_INFO );
225
226 $handler = null;
227 if ( $http->hasSessionVariable( self::LAST_HANDLER_NAME ) )
228 {
229 $handlerName = $http->sessionVariable( self::LAST_HANDLER_NAME );
230 $handler = eZUserLoginHandler::instance( $handlerName );
231 }
232 if ( $handler )
233 {
234 return $handler->preCollectUserInfo();
235 }
236 else
237 {
238 $redirect =& $http->sessionVariable( self::LAST_CHECK_REDIRECT );
239 if ( !$redirect )
240 {
241 $redirect = array( 'module' => 'user', 'function' => 'login' );
242 }
243 return $redirect;
244 }
245 } break;
246
247 case self::STEP_POST_COLLECT_USER_INFO:
248 {
249 $http->setSessionVariable( self::STEP, self::STEP_LOGIN_USER );
250
251 $handler = null;
252 if ( $http->hasSessionVariable( self::LAST_HANDLER_NAME ) )
253 {
254 $handlerName = $http->sessionVariable( self::LAST_HANDLER_NAME );
255 $handler = eZUserLoginHandler::instance( $handlerName );
256 }
257
258 if ( $handler ) //and $handlerName != 'standard' )
259 {
260 // Use specified login handler to handle Login info input
261 if ( !$handler->postCollectUserInfo() ) // Catch cancel of information collection
262 {
263 eZUserLoginHandler::sessionCleanup();
264 eZHTTPTool::redirect( '/' );
265 eZExecution::cleanExit();
266 }
267 }
268 return eZUserLoginHandler::checkUser( $siteBasics, $url );
269 } break;
270
271 case self::STEP_LOGIN_USER:
272 {
273 $ini = eZINI::instance();
274 $handlerList = array( 'standard' );
275 if ( $ini->hasVariable( 'UserSettings', 'LoginHandler' ) )
276 {
277 $handlerList = $ini->variable( 'UserSettings', 'LoginHandler' );
278 }
279
280 $userInfoArray =& $http->sessionVariable( self::USER_INFO );
281 $http->removeSessionVariable( self::USER_INFO );
282
283 if ( $http->hasSessionVariable( self::FORCE_LOGIN ) )
284 {
285 $http->removeSessionVariable( self::FORCE_LOGIN );
286 }
287
288 $user = null;
289 if ( is_array( $userInfoArray ) and $userInfoArray['login'] and $userInfoArray['password'] )
290 {
291 foreach( $handlerList as $handler )
292 {
293 $userObject = eZUserLoginHandler::instance( $handler );
294 if ( $userObject )
295 {
296 $user = $userObject->loginUser( $userInfoArray['login'], $userInfoArray['password'] );
297 if ( is_subclass_of( $user, 'eZUser' ) )
298 {
299 eZUserLoginHandler::sessionCleanup();
300 return null;
301 }
302 else if ( is_array( $user ) )
303 {
304 eZUserLoginHandler::sessionCleanup();
305 return $user;
306 }
307 }
308 }
309 }
310
311 $http->setSessionVariable( self::STEP, self::STEP_PRE_CHECK_USER_INFO );
312 return eZUserLoginHandler::checkUser( $siteBasics, $url );
313 } break;
314 }
315 }
316
320 static function forceLogin()
321 {
322 $http = eZHTTPTool::instance();
323 $http->setSessionVariable( self::FORCE_LOGIN, 1 );
324 }
325 }
326
327 ?>
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZExecution\cleanExit
static cleanExit()
Definition: ezexecution.php:100
eZExtension\expandedPathList
static expandedPathList( $extensionList, $subdirectory=false)
Definition: ezextension.php:334
eZHTTPTool\redirect
static redirect( $path, $parameters=array(), $status=false, $encodeURL=true, $returnRedirectObject=false)
Definition: ezhttptool.php:593
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZURI
Definition: ezuri.php:28
eZUserLoginHandler
The class eZUserLoginHandler does.
Definition: ezuserloginhandler.php:19
eZUserLoginHandler\LAST_HANDLER_NAME
const LAST_HANDLER_NAME
Definition: ezuserloginhandler.php:25
eZUserLoginHandler\STEP_CHECK_USER
const STEP_CHECK_USER
Definition: ezuserloginhandler.php:30
eZUserLoginHandler\sessionCleanup
static sessionCleanup()
Definition: ezuserloginhandler.php:37
eZUserLoginHandler\preCheck
static preCheck(array &$siteBasics, eZURI $uri)
Definition: ezuserloginhandler.php:135
eZUserLoginHandler\LAST_CHECK_REDIRECT
const LAST_CHECK_REDIRECT
Definition: ezuserloginhandler.php:23
eZUserLoginHandler\STEP_LOGIN_USER
const STEP_LOGIN_USER
Definition: ezuserloginhandler.php:31
eZUserLoginHandler\AVAILABLE_ARRAY
const AVAILABLE_ARRAY
Definition: ezuserloginhandler.php:20
eZUserLoginHandler\checkUser
static checkUser(&$siteBasics, &$url)
Definition: ezuserloginhandler.php:169
eZUserLoginHandler\instance
static instance( $protocol="standard")
Definition: ezuserloginhandler.php:80
eZUserLoginHandler\STEP_PRE_COLLECT_USER_INFO
const STEP_PRE_COLLECT_USER_INFO
Definition: ezuserloginhandler.php:28
eZUserLoginHandler\STEP
const STEP
Definition: ezuserloginhandler.php:21
eZUserLoginHandler\STEP_PRE_CHECK_USER_INFO
const STEP_PRE_CHECK_USER_INFO
Definition: ezuserloginhandler.php:27
eZUserLoginHandler\USER_INFO
const USER_INFO
Definition: ezuserloginhandler.php:22
eZUserLoginHandler\FORCE_LOGIN
const FORCE_LOGIN
Definition: ezuserloginhandler.php:24
eZUserLoginHandler\forceLogin
static forceLogin()
Definition: ezuserloginhandler.php:320
eZUserLoginHandler\STEP_POST_COLLECT_USER_INFO
const STEP_POST_COLLECT_USER_INFO
Definition: ezuserloginhandler.php:29
eZUser
eZUser handles eZ Publish user accounts
Definition: ezuser.php:19
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.