Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezuser.php
Go to the documentation of this file.
1 <?php
18 class eZUser extends eZPersistentObject
19 {
20 public $GroupsAsObjects;
22 const PASSWORD_HASH_EMPTY = 0;
24 const PASSWORD_HASH_MD5_PASSWORD = 1;
26 const PASSWORD_HASH_MD5_USER = 2;
28 const PASSWORD_HASH_MD5_SITE = 3;
31 const PASSWORD_HASH_MYSQL = 4;
33 const PASSWORD_HASH_PLAINTEXT = 5;
35 const PASSWORD_HASH_BCRYPT = 6;
37 const PASSWORD_HASH_PHP_DEFAULT = 7;
38
41 const DEFAULT_PASSWORD_HASH = self::PASSWORD_HASH_PHP_DEFAULT;
42
48 const AUTH_STRING_MAX_LENGTH = 4096;
49
51 const AUTHENTICATE_LOGIN = 1;
53 const AUTHENTICATE_EMAIL = 2;
54
55 const AUTHENTICATE_ALL = 3; //EZ_USER_AUTHENTICATE_LOGIN | EZ_USER_AUTHENTICATE_EMAIL;
56
63 const NO_SESSION_REGENERATE = 1;
64
65 protected static $anonymousId = null;
66
67 public function __construct( $row = array() )
68 {
69 parent::__construct( $row );
70 $this->OriginalPassword = false;
71 $this->OriginalPasswordConfirm = false;
72 }
73
78 function eZUser( $row = array() )
79 {
80 self::__construct( $row );
81 }
82
83 static function definition()
84 {
85 static $definition = array( 'fields' => array( 'contentobject_id' => array( 'name' => 'ContentObjectID',
86 'datatype' => 'integer',
87 'default' => 0,
88 'required' => true,
89 'foreign_class' => 'eZContentObject',
90 'foreign_attribute' => 'id',
91 'multiplicity' => '0..1' ),
92 'login' => array( 'name' => 'Login',
93 'datatype' => 'string',
94 'default' => '',
95 'required' => true ),
96 'email' => array( 'name' => 'Email',
97 'datatype' => 'string',
98 'default' => '',
99 'required' => true ),
100 'password_hash' => array( 'name' => 'PasswordHash',
101 'datatype' => 'string',
102 'default' => '',
103 'required' => true ),
104 'password_hash_type' => array( 'name' => 'PasswordHashType',
105 'datatype' => 'integer',
106 'default' => 1,
107 'required' => true ) ),
108 'keys' => array( 'contentobject_id' ),
109 'sort' => array( 'contentobject_id' => 'asc' ),
110 'function_attributes' => array( 'contentobject' => 'contentObject',
111 'account_key' => 'accountKey',
112 'groups' => 'groups',
113 'has_stored_login' => 'hasStoredLogin',
114 'original_password' => 'originalPassword',
115 'original_password_confirm' => 'originalPasswordConfirm',
116 'roles' => 'roles',
117 'role_id_list' => 'roleIDList',
118 'limited_assignment_value_list' => 'limitValueList',
119 'is_logged_in' => 'isRegistered',
120 'is_enabled' => 'isEnabled',
121 'is_locked' => 'isLocked',
122 'last_visit' => 'lastVisit',
123 'login_count' => 'loginCount',
124 'has_manage_locations' => 'hasManageLocations' ),
125 'relations' => array( 'contentobject_id' => array( 'class' => 'ezcontentobject',
126 'field' => 'id' ) ),
127 'class_name' => 'eZUser',
128 'name' => 'ezuser' );
129 return $definition;
130 }
131
135 static function passwordHashTypeName( $id )
136 {
137 switch ( $id )
138 {
139 case self::PASSWORD_HASH_EMPTY:
140 {
141 return 'empty';
142 } break;
143 case self::PASSWORD_HASH_MD5_PASSWORD:
144 {
145 return 'md5_password';
146 } break;
147 case self::PASSWORD_HASH_MD5_USER:
148 {
149 return 'md5_user';
150 } break;
151 case self::PASSWORD_HASH_MD5_SITE:
152 {
153 return 'md5_site';
154 } break;
155 case self::PASSWORD_HASH_MYSQL:
156 {
157 return 'mysql';
158 } break;
159 case self::PASSWORD_HASH_PLAINTEXT:
160 {
161 return 'plaintext';
162 } break;
163 case self::PASSWORD_HASH_BCRYPT:
164 {
165 return 'bcrypt';
166 } break;
167 case self::PASSWORD_HASH_PHP_DEFAULT:
168 {
169 return 'php_default';
170 } break;
171 }
172 }
173
177 static function passwordHashTypeID( $identifier )
178 {
179 switch ( $identifier )
180 {
181 case 'empty':
182 {
183 return self::PASSWORD_HASH_EMPTY;
184 } break;
185 case 'md5_password':
186 {
187 return self::PASSWORD_HASH_MD5_PASSWORD;
188 } break;
189 case 'md5_user':
190 {
191 return self::PASSWORD_HASH_MD5_USER;
192 } break;
193 case 'md5_site':
194 {
195 return self::PASSWORD_HASH_MD5_SITE;
196 } break;
197 case 'mysql':
198 {
199 return self::PASSWORD_HASH_MYSQL;
200 } break;
201 case 'plaintext':
202 {
203 return self::PASSWORD_HASH_PLAINTEXT;
204 } break;
205 case 'bcrypt':
206 {
207 return self::PASSWORD_HASH_BCRYPT;
208 } break;
209 case 'php_default':
210 {
211 return self::PASSWORD_HASH_PHP_DEFAULT;
212 } break;
213 default:
214 {
215 eZDebug::writeError( "Password hash type identifier '$identifier' is not recognized. " .
216 'Check the site.ini [UserSettings] HashType setting. ' .
217 'Defaulting to ' . self::passwordHashTypeName( self::DEFAULT_PASSWORD_HASH ) );
218 return self::DEFAULT_PASSWORD_HASH;
219 }
220 }
221 }
222
226 function hasManageLocations()
227 {
228 $accessResult = $this->hasAccessTo( 'content', 'manage_locations' );
229 if ( $accessResult['accessWord'] != 'no' )
230 {
231 return true;
232 }
233
234 return false;
235 }
236
237 static function create( $contentObjectID )
238 {
239 $row = array(
240 'contentobject_id' => $contentObjectID,
241 'login' => null,
242 'email' => null,
243 'password_hash' => null,
244 'password_hash_type' => null
245 );
246 return new eZUser( $row );
247 }
248
254 public function store( $fieldFilters = null )
255 {
256 $this->Email = trim( $this->Email );
257 $userID = $this->attribute( 'contentobject_id' );
258 // Clear memory cache
259 unset( $GLOBALS['eZUserObject_' . $userID] );
260 $GLOBALS['eZUserObject_' . $userID] = $this;
261 self::purgeUserCacheByUserId( $userID );
262
263 if ( $this->Login )
264 {
265 parent::store( $fieldFilters );
266 }
267 }
268
269 function originalPassword()
270 {
271 return $this->OriginalPassword;
272 }
273
274 function setOriginalPassword( $password )
275 {
276 $this->OriginalPassword = $password;
277 }
278
279 function originalPasswordConfirm()
280 {
281 return $this->OriginalPasswordConfirm;
282 }
283
284 function setOriginalPasswordConfirm( $password )
285 {
286 $this->OriginalPasswordConfirm = $password;
287 }
288
289 function hasStoredLogin()
290 {
291 $db = eZDB::instance();
292 $contentObjectID = $this->attribute( 'contentobject_id' );
293 $sql = "SELECT * FROM ezuser WHERE contentobject_id='$contentObjectID' AND LENGTH( login ) > 0";
294 $rows = $db->arrayQuery( $sql );
295 if ( !empty( $rows ) )
296 {
297 return true;
298 }
299
300 // If there are no stored logins, we look for a "draft" login before we give up
301 $userObject = eZContentObject::fetch( $contentObjectID );
302 if ( $userObject instanceof eZContentObject )
303 {
304 foreach ( $userObject->attribute( 'contentobject_attributes' ) as $contentObjectAttribute )
305 {
306 if ( $contentObjectAttribute->attribute( 'data_type_string' ) === 'ezuser' )
307 {
308 $serializedDraft = $contentObjectAttribute->attribute( 'data_text' );
309 return !empty( $serializedDraft );
310 }
311 }
312 }
313
314 return false;
315 }
316
321 function setInformation( $id, $login, $email, $password, $passwordConfirm = false )
322 {
323 $this->setAttribute( "contentobject_id", $id );
324 $this->setAttribute( "email", $email );
325 $this->setAttribute( "login", $login );
326 if ( eZUser::validatePassword( $password ) and
327 $password === $passwordConfirm ) // Cannot change login or password_hash without login and password
328 {
329 if ( eZUser::hashType() !== self::PASSWORD_HASH_EMPTY )
330 {
331 $this->setAttribute(
332 "password_hash",
333 eZUser::createHash( $login, $password, eZUser::site(), eZUser::hashType() )
334 );
335 }
336
337 $this->setAttribute( "password_hash_type", eZUser::hashType() );
338 }
339 else
340 {
341 $this->setOriginalPassword( $password );
342 $this->setOriginalPasswordConfirm( $passwordConfirm );
343 }
344 }
345
351 static function fetch( $id, $asObject = true )
352 {
353 if ( !$id )
354 return null;
355 return eZPersistentObject::fetchObject( eZUser::definition(),
356 null,
357 array( 'contentobject_id' => $id ),
358 $asObject );
359 }
360
361 static function fetchByName( $login, $asObject = true )
362 {
363 return eZPersistentObject::fetchObject( eZUser::definition(),
364 null,
365 array( 'LOWER( login )' => strtolower( $login ) ),
366 $asObject );
367 }
368
369 static function fetchByEmail( $email, $asObject = true )
370 {
371 return eZPersistentObject::fetchObject( eZUser::definition(),
372 null,
373 array( 'LOWER( email )' => strtolower( $email ) ),
374 $asObject );
375 }
376
387 static public function fetchUnactivated( $sort = false, $limit = 10, $offset = 0 )
388 {
389 $accountDef = eZUserAccountKey::definition();
390 $settingsDef = eZUserSetting::definition();
391
392 return eZPersistentObject::fetchObjectList(
393 eZUser::definition(), null, null, $sort,
394 array(
395 'limit' => $limit,
396 'offset' => $offset
397 ),
398 true, false, null,
399 array( $accountDef['name'], $settingsDef['name'] ),
400 " WHERE contentobject_id = {$accountDef['name']}.user_id"
401 . " AND {$settingsDef['name']}.user_id = contentobject_id"
402 . " AND is_enabled = 0"
403 );
404 }
405
413 static function fetchLoggedInList( $asObject = false, $offset = false, $limit = false, $sortBy = false )
414 {
415 $db = eZDB::instance();
416 $time = time() - eZINI::instance()->variable( 'Session', 'ActivityTimeout' );
417
418 $parameters = array();
419 if ( $offset )
420 $parameters['offset'] =(int) $offset;
421 if ( $limit )
422 $parameters['limit'] =(int) $limit;
423 $sortText = '';
424 if ( $asObject )
425 {
426 $selectArray = array( "distinct ezuser.*" );
427 }
428 else
429 {
430 $selectArray = array( "ezuser.contentobject_id as user_id", "ezcontentobject.name" );
431 }
432 if ( $sortBy !== false )
433 {
434 $sortElements = array();
435 if ( !is_array( $sortBy ) )
436 {
437 $sortBy = array( array( $sortBy, true ) );
438 }
439 else if ( !is_array( $sortBy[0] ) )
440 $sortBy = array( $sortBy );
441 $sortColumns = array();
442 foreach ( $sortBy as $sortElements )
443 {
444 $sortColumn = $sortElements[0];
445 $sortOrder = $sortElements[1];
446 $orderText = $sortOrder ? 'asc' : 'desc';
447 switch ( $sortColumn )
448 {
449 case 'user_id':
450 {
451 $sortColumn = "ezuser.contentobject_id $orderText";
452 } break;
453
454 case 'login':
455 {
456 $sortColumn = "ezuser.login $orderText";
457 } break;
458
459 case 'activity':
460 {
461 $selectArray[] = "ezuservisit.current_visit_timestamp AS activity";
462 $sortColumn = "activity $orderText";
463 } break;
464
465 case 'email':
466 {
467 $sortColumn = "ezuser.email $orderText";
468 } break;
469
470 default:
471 {
472 eZDebug::writeError( "Unkown sort column '$sortColumn'", __METHOD__ );
473 $sortColumn = false;
474 } break;
475 }
476 if ( $sortColumn )
477 $sortColumns[] = $sortColumn;
478 }
479 if ( !empty( $sortColumns ) )
480 $sortText = "ORDER BY " . implode( ', ', $sortColumns );
481 }
482 if ( $asObject )
483 {
484 $selectText = implode( ', ', $selectArray );
485 $sql = "SELECT $selectText
486 FROM ezuservisit, ezuser
487 WHERE ezuservisit.user_id != '" . self::anonymousId() . "' AND
488 ezuservisit.current_visit_timestamp > '$time' AND
489 ezuser.contentobject_id = ezuservisit.user_id
490 $sortText";
491 $rows = $db->arrayQuery( $sql, $parameters );
492 $list = array();
493 foreach ( $rows as $row )
494 {
495 $list[] = new eZUser( $row );
496 }
497 }
498 else
499 {
500 $selectText = implode( ', ', $selectArray );
501 $sql = "SELECT $selectText
502 FROM ezuservisit, ezuser, ezcontentobject
503 WHERE ezuservisit.user_id != '" . self::anonymousId() . "' AND
504 ezuservisit.current_visit_timestamp > '$time' AND
505 ezuser.contentobject_id = ezuservisit.user_id AND
506 ezcontentobject.id = ezuser.contentobject_id
507 $sortText";
508 $rows = $db->arrayQuery( $sql, $parameters );
509 $list = array();
510 foreach ( $rows as $row )
511 {
512 $list[$row['user_id']] = $row['name'];
513 }
514 }
515 return $list;
516 }
517
523 static function fetchLoggedInCount()
524 {
525 if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and
526 !$GLOBALS['eZSiteBasics']['no-cache-adviced'] and
527 isset( $GLOBALS['eZUserLoggedInCount'] ) )
528 return $GLOBALS['eZUserLoggedInCount'];
529 $db = eZDB::instance();
530 $time = time() - eZINI::instance()->variable( 'Session', 'ActivityTimeout' );
531
532 $sql = "SELECT count( DISTINCT user_id ) as count
533 FROM ezuservisit
534 WHERE user_id != '" . self::anonymousId() . "' AND
535 user_id > 0 AND
536 current_visit_timestamp > '$time'";
537 $rows = $db->arrayQuery( $sql );
538 $count = isset( $rows[0] ) ? $rows[0]['count'] : 0;
539 $GLOBALS['eZUserLoggedInCount'] = $count;
540 return $count;
541 }
542
549 static function fetchAnonymousCount()
550 {
551 if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and
552 !$GLOBALS['eZSiteBasics']['no-cache-adviced'] and
553 isset( $GLOBALS['eZUserAnonymousCount'] ) )
554 return $GLOBALS['eZUserAnonymousCount'];
555 $db = eZDB::instance();
556 $time = time();
557 $ini = eZINI::instance();
558 $activityTimeout = $ini->variable( 'Session', 'ActivityTimeout' );
559 $sessionTimeout = $ini->variable( 'Session', 'SessionTimeout' );
560 $time = $time + $sessionTimeout - $activityTimeout;
561
562 $sql = "SELECT count( session_key ) as count
563 FROM ezsession
564 WHERE user_id = '" . self::anonymousId() . "' AND
565 expiration_time > '$time'";
566 $rows = $db->arrayQuery( $sql );
567 $count = isset( $rows[0] ) ? $rows[0]['count'] : 0;
568 $GLOBALS['eZUserAnonymousCount'] = $count;
569 return $count;
570 }
571
578 static function isUserLoggedIn( $userID )
579 {
580 $userID = (int)$userID;
581 if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and
582 !$GLOBALS['eZSiteBasics']['no-cache-adviced'] and
583 isset( $GLOBALS['eZUserLoggedInMap'][$userID] ) )
584 return $GLOBALS['eZUserLoggedInMap'][$userID];
585 $db = eZDB::instance();
586 $time = time() - eZINI::instance()->variable( 'Session', 'ActivityTimeout' );
587
588 $sql = "SELECT DISTINCT user_id
589 FROM ezuservisit
590 WHERE user_id = '" . $userID . "' AND
591 current_visit_timestamp > '$time'";
592 $rows = $db->arrayQuery( $sql, array( 'limit' => 2 ) );
593 $isLoggedIn = isset( $rows[0] );
594 $GLOBALS['eZUserLoggedInMap'][$userID] = $isLoggedIn;
595 return $isLoggedIn;
596 }
597
605 static function clearSessionCache()
606 {
607 unset( $GLOBALS['eZUserLoggedInCount'] );
608 unset( $GLOBALS['eZUserAnonymousCount'] );
609 unset( $GLOBALS['eZUserLoggedInMap'] );
610 }
611
619 static function removeSessionData( $userID )
620 {
621 eZUser::clearSessionCache();
622 eZSession::getHandlerInstance()->deleteByUserIDs( array( $userID ) );
623 }
624
629 static function removeUser( $userID )
630 {
631 $user = eZUser::fetch( $userID );
632 if ( !$user )
633 {
634 eZDebug::writeError( "unable to find user with ID $userID", __METHOD__ );
635 return false;
636 }
637
638 eZUser::removeSessionData( $userID );
639
640 eZSubtreeNotificationRule::removeByUserID( $userID );
641 eZCollaborationNotificationRule::removeByUserID( $userID );
642 eZUserSetting::removeByUserID( $userID );
643 eZUserAccountKey::removeByUserID( $userID );
644 eZForgotPassword::removeByUserID( $userID );
645 eZWishList::removeByUserID( $userID );
646 eZGeneralDigestUserSettings::removeByUserId( $userID );
647
648 eZPersistentObject::removeObject( eZUser::definition(),
649 array( 'contentobject_id' => $userID ) );
650 return true;
651 }
652
657 static function fetchContentList()
658 {
659 $contentObjectStatus = eZContentObject::STATUS_PUBLISHED;
660 $query = "SELECT ezcontentobject.*
661 FROM ezuser, ezcontentobject, ezuser_setting
662 WHERE ezcontentobject.status = '$contentObjectStatus' AND
663 ezuser_setting.is_enabled = 1 AND
664 ezcontentobject.id = ezuser.contentobject_id AND
665 ezuser_setting.user_id = ezuser.contentobject_id";
666 $db = eZDB::instance();
667 $rows = $db->arrayQuery( $query );
668 return $rows;
669 }
670
675 static function hashType()
676 {
677 $ini = eZINI::instance();
678 $type = strtolower( $ini->variable( 'UserSettings', 'HashType' ) );
679
680 return self::passwordHashTypeID( $type );
681 }
682
687 static function site()
688 {
689 $ini = eZINI::instance();
690 return $ini->variable( 'UserSettings', 'SiteName' );
691 }
692
697 static function fetchBuiltin( $id )
698 {
699 if ( !in_array( $id, $GLOBALS['eZUserBuiltins'] ) )
700 $id = self::anonymousId();
701 if ( empty( $GLOBALS["eZUserBuilitinInstance-$id"] ) )
702 {
703 $GLOBALS["eZUserBuilitinInstance-$id"] = eZUser::fetch( self::anonymousId() );
704 }
705 return $GLOBALS["eZUserBuilitinInstance-$id"];
706 }
707
711 function id()
712 {
713 return $this->ContentObjectID;
714 }
715
719 static function authenticationMatch()
720 {
721 $ini = eZINI::instance();
722 $matchArray = $ini->variableArray( 'UserSettings', 'AuthenticateMatch' );
723 $match = 0;
724 foreach ( $matchArray as $matchItem )
725 {
726 switch ( $matchItem )
727 {
728 case "login":
729 {
730 $match = ( $match | self::AUTHENTICATE_LOGIN );
731 } break;
732 case "email":
733 {
734 $match = ( $match | self::AUTHENTICATE_EMAIL );
735 } break;
736 }
737 }
738 return $match;
739 }
740
744 static function requireUniqueEmail()
745 {
746 $ini = eZINI::instance();
747 return $ini->variable( 'UserSettings', 'RequireUniqueEmail' ) == 'true';
748 }
749
758 public static function loginUser( $login, $password, $authenticationMatch = false )
759 {
760 $user = self::_loginUser( $login, $password, $authenticationMatch );
761
762 if ( is_object( $user ) )
763 {
764 self::loginSucceeded( $user );
765 return $user;
766 }
767 else
768 {
769 self::loginFailed( $user, $login );
770 return false;
771 }
772 }
773
779 protected static function loginSucceeded( $user )
780 {
781 $userID = $user->attribute( 'contentobject_id' );
782
783 // if audit is enabled logins should be logged
784 eZAudit::writeAudit( 'user-login', array( 'User id' => $userID, 'User login' => $user->attribute( 'login' ) ) );
785
786 eZUser::updateLastVisit( $userID, true );
787 eZUser::setCurrentlyLoggedInUser( $user, $userID );
788
789 // Reset number of failed login attempts
790 eZUser::setFailedLoginAttempts( $userID, 0 );
791 }
792
799 protected static function loginFailed( $userID, $login )
800 {
801 $loginEscaped = eZDB::instance()->escapeString( $login );
802
803 // Failed login attempts should be logged
804 eZAudit::writeAudit( 'user-failed-login', array( 'User login' => $loginEscaped,
805 'Comment' => 'Failed login attempt: eZUser::loginUser()' ) );
806
807 // Increase number of failed login attempts.
808 if ( $userID )
809 eZUser::setFailedLoginAttempts( $userID );
810 }
811
825 protected static function _loginUser( $login, $password, $authenticationMatch = false )
826 {
827 if ( $login == '' || $password == '' )
828 {
829 return false;
830 }
831
832 $http = eZHTTPTool::instance();
833 $db = eZDB::instance();
834
835 if ( $authenticationMatch === false )
836 $authenticationMatch = eZUser::authenticationMatch();
837
838 $login = self::trimAuthString( $login );
839 $password = self::trimAuthString( $password );
840
841 $loginEscaped = $db->escapeString( $login );
842 $passwordEscaped = $db->escapeString( $password );
843
844 $loginArray = array();
845 if ( $authenticationMatch & self::AUTHENTICATE_LOGIN )
846 $loginArray[] = "login='$loginEscaped'";
847 if ( $authenticationMatch & self::AUTHENTICATE_EMAIL )
848 {
849 if ( eZMail::validate( $login ) )
850 {
851 $loginArray[] = "email='$loginEscaped'";
852 }
853 }
854 if ( empty( $loginArray ) )
855 $loginArray[] = "login='$loginEscaped'";
856 $loginText = implode( ' OR ', $loginArray );
857
858 $contentObjectStatus = eZContentObject::STATUS_PUBLISHED;
859
860 // PASSWORD_HASH_MYSQL is handled further down as this inital SQL needs to work on MySQL 8.0 as well as PostgreSQL
861 $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login
862 FROM ezuser, ezcontentobject
863 WHERE ( $loginText )
864 AND password_hash_type!=0
865 AND ezcontentobject.status='$contentObjectStatus'
866 AND ezcontentobject.id=contentobject_id";
867
868 $users = $db->arrayQuery( $query );
869 $exists = false;
870 if ( $users !== false && isset( $users[0] ) )
871 {
872 $ini = eZINI::instance();
873 foreach ( $users as $userRow )
874 {
875 $userID = $userRow['contentobject_id'];
876 $hashType = $userRow['password_hash_type'];
877 $hash = $userRow['password_hash'];
878 $exists = eZUser::authenticateHash( $userRow['login'], $password, eZUser::site(),
879 $hashType,
880 $hash );
881
882 $databaseName = $db->databaseName();
883 // If hash type is MySql
884 if ( $hashType == self::PASSWORD_HASH_MYSQL and $databaseName === 'mysql' )
885 {
886 $queryMysqlUser = "SELECT contentobject_id, password_hash, password_hash_type, email, login
887 FROM ezuser, ezcontentobject
888 WHERE ezcontentobject.status='$contentObjectStatus' AND
889 password_hash_type=4 AND ( $loginText ) AND password_hash=PASSWORD('$passwordEscaped') ";
890 $mysqlUsers = $db->arrayQuery( $queryMysqlUser );
891 if ( isset( $mysqlUsers[0] ) )
892 $exists = true;
893
894 }
895
896 // If current user has been disabled after a few failed login attempts.
897 $canLogin = eZUser::isEnabledAfterFailedLogin( $userID );
898
899 if ( $exists )
900 {
901 eZDebugSetting::writeDebug( 'kernel-user', eZUser::createHash( $userRow['login'], $password, eZUser::site(),
902 $hashType, $hash ), "check hash" );
903 eZDebugSetting::writeDebug( 'kernel-user', $hash, "stored hash" );
904
905 // We should store userID for warning message.
906 $GLOBALS['eZFailedLoginAttemptUserID'] = $userID;
907
908 $userSetting = eZUserSetting::fetch( $userID );
909 $isEnabled = $userSetting->attribute( "is_enabled" );
910 if ( $hashType != eZUser::hashType() and
911 strtolower( $ini->variable( 'UserSettings', 'UpdateHash' ) ) == 'true' )
912 {
913 $hashType = eZUser::hashType();
914 $hash = eZUser::createHash( $userRow['login'], $password, eZUser::site(),
915 $hashType );
916 $db->query( "UPDATE ezuser SET password_hash='$hash', password_hash_type='$hashType' WHERE contentobject_id='$userID'" );
917 }
918 break;
919 }
920 }
921 }
922
923 if ( $exists and $isEnabled and $canLogin )
924 {
925 return new eZUser( $userRow );
926 }
927 else
928 {
929 return isset( $userID ) ? $userID : false;
930 }
931 }
932
937 static function isUserIPInList( $ipList )
938 {
939 $ipAddress = eZSys::clientIP();
940 if ( $ipAddress )
941 {
942 $result = false;
943 foreach( $ipList as $itemToMatch )
944 {
945 if ( preg_match("/^(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))(\/([0-9]+)$|$)/", $itemToMatch, $matches ) )
946 {
947 if ( $matches[6] )
948 {
949 if ( eZDebug::isIPInNet( $ipAddress, $matches[1], $matches[7] ) )
950 {
951 $result = true;
952 break;
953 }
954 }
955 else
956 {
957 if ( $matches[1] == $ipAddress )
958 {
959 $result = true;
960 break;
961 }
962 }
963 }
964 }
965 }
966 else
967 {
968 $result = (
969 in_array( 'commandline', $ipList ) &&
970 ( php_sapi_name() == 'cli' )
971 );
972 }
973 return $result;
974 }
975
980 static function isTrusted()
981 {
982 $ini = eZINI::instance();
983
984 // Check if current user is trusted user.
985 $trustedIPs = $ini->hasVariable( 'UserSettings', 'TrustedIPList' ) ? $ini->variable( 'UserSettings', 'TrustedIPList' ) : array();
986
987 // Check if IP address of current user is in $trustedIPs array.
988 $trustedUser = eZUser::isUserIPInList( $trustedIPs );
989 if ( $trustedUser )
990 return true;
991
992 return false;
993 }
994
999 static function maxNumberOfFailedLogin()
1000 {
1001 $ini = eZINI::instance();
1002
1003 $maxNumberOfFailedLogin = $ini->hasVariable( 'UserSettings', 'MaxNumberOfFailedLogin' ) ? $ini->variable( 'UserSettings', 'MaxNumberOfFailedLogin' ) : '0';
1004 return $maxNumberOfFailedLogin;
1005 }
1006
1007 /*
1008 \static
1009 Returns true if the user can login
1010 If user has number of failed login attempts more than eZUser::maxNumberOfFailedLogin()
1011 and user is not trusted
1012 the user will not be allowed to login.
1013 */
1014 static function isEnabledAfterFailedLogin( $userID, $ignoreTrusted = false )
1015 {
1016 if ( !is_numeric( $userID ) )
1017 return true;
1018
1019 $userObject = eZUser::fetch( $userID );
1020 if ( !$userObject )
1021 return true;
1022
1023 $trustedUser = eZUser::isTrusted();
1024 // If user is trusted we should stop processing
1025 if ( $trustedUser and !$ignoreTrusted )
1026 return true;
1027
1028 $maxNumberOfFailedLogin = eZUser::maxNumberOfFailedLogin();
1029
1030 if ( $maxNumberOfFailedLogin == '0' )
1031 return true;
1032
1033 $failedLoginAttempts = $userObject->failedLoginAttempts();
1034 if ( $failedLoginAttempts > $maxNumberOfFailedLogin )
1035 return false;
1036
1037 return true;
1038 }
1039
1054 static function setCurrentlyLoggedInUser( $user, $userID, $flags = 0 )
1055 {
1056 $GLOBALS["eZUserGlobalInstance_$userID"] = $user;
1057 // Set/overwrite the global user, this will be accessed from
1058 // instance() when there is no ID passed to the function.
1059 $GLOBALS["eZUserGlobalInstance_"] = $user;
1060 eZSession::setUserID( $userID );
1061
1062 if ( !( $flags & self::NO_SESSION_REGENERATE) )
1063 eZSession::regenerate();
1064
1065 eZSession::set( 'eZUserLoggedInID', $userID );
1066 self::cleanup();
1067 }
1068
1073 function sessionCleanup()
1074 {
1075 }
1076
1082 static function cleanup()
1083 {
1084 $http = eZHTTPTool::instance();
1085
1086 $http->removeSessionVariable( 'CanInstantiateClassList' );
1087 $http->removeSessionVariable( 'ClassesCachedForUser' );
1088
1089 // Note: This must be done more generic with an internal
1090 // callback system.
1091 eZPreferences::sessionCleanup();
1092 }
1093
1097 function loginCurrent()
1098 {
1099 self::setCurrentlyLoggedInUser( $this, $this->ContentObjectID );
1100 }
1101
1106 static function logoutCurrent()
1107 {
1108 $http = eZHTTPTool::instance();
1109 $id = false;
1110 $GLOBALS["eZUserGlobalInstance_$id"] = false;
1111 $contentObjectID = $http->sessionVariable( 'eZUserLoggedInID' );
1112
1113 // reset session data
1114 $newUserID = self::anonymousId();
1115 eZSession::setUserID( $newUserID );
1116 $http->setSessionVariable( 'eZUserLoggedInID', $newUserID );
1117
1118 // Clear current basket if necessary
1119 $db = eZDB::instance();
1120 $db->begin();
1121 eZBasket::cleanupCurrentBasket();
1122 $db->commit();
1123
1124 if ( $contentObjectID )
1125 {
1126 //set last visit to minus
1127 self::updateLastVisitByLogout( $contentObjectID );
1128 //clean up sessions
1129 self::cleanup();
1130 }
1131
1132 // give user new session id
1133 eZSession::regenerate();
1134
1135 // set the property used to prevent SSO from running again
1136 self::$userHasLoggedOut = true;
1137 }
1138
1147 static function updateLastVisitByLogout( $userID )
1148 {
1149 $db = eZDB::instance();
1150 $db->query( "UPDATE ezuservisit SET current_visit_timestamp=-ABS(current_visit_timestamp) WHERE user_id=$userID" );
1151 }
1152
1163 static function instance( $id = false )
1164 {
1165 if ( !empty( $GLOBALS["eZUserGlobalInstance_$id"] ) )
1166 {
1167 return $GLOBALS["eZUserGlobalInstance_$id"];
1168 }
1169
1170 $userId = $id;
1171 $currentUser = null;
1172 $http = eZHTTPTool::instance();
1173 $anonymousUserID = self::anonymousId();
1174 $sessionHasStarted = eZSession::hasStarted();
1175 // If not specified get the current user
1176 if ( $userId === false )
1177 {
1178 if ( $sessionHasStarted )
1179 {
1180 $userId = $http->sessionVariable( 'eZUserLoggedInID' );
1181 if ( !is_numeric( $userId ) )
1182 {
1183 $userId = $anonymousUserID;
1184 eZSession::setUserID( $userId );
1185 $http->setSessionVariable( 'eZUserLoggedInID', $userId );
1186 }
1187 }
1188 else
1189 {
1190 $userId = $anonymousUserID;
1191 eZSession::setUserID( $userId );
1192 }
1193 }
1194
1195 // Check user cache (this effectivly fetches user from cache)
1196 // user not found if !isset( isset( $userCache['info'][$userId] ) )
1197 $userCache = self::getUserCacheByUserId( $userId );
1198 if ( isset( $userCache['info'][$userId] ) )
1199 {
1200 $userArray = $userCache['info'][$userId];
1201 if ( is_numeric( $userArray['contentobject_id'] ) )
1202 {
1203 $currentUser = new eZUser( $userArray );
1204 $currentUser->setUserCache( $userCache );
1205 }
1206 }
1207
1208 $ini = eZINI::instance();
1209 // Check if:
1210 // - the user has not logged out,
1211 // - the user is not logged in,
1212 // - and if a automatic single sign on plugin is enabled.
1213 if ( !self::$userHasLoggedOut && is_object( $currentUser ) && !$currentUser->isRegistered() )
1214 {
1215 $ssoHandlerArray = $ini->variable( 'UserSettings', 'SingleSignOnHandlerArray' );
1216 if ( !empty( $ssoHandlerArray ) )
1217 {
1218 $ssoUser = false;
1219 foreach ( $ssoHandlerArray as $ssoHandler )
1220 {
1221 $className = 'eZ' . $ssoHandler . 'SSOHandler';
1222 if( class_exists( $className ) )
1223 {
1224 $impl = new $className();
1225 $ssoUser = $impl->handleSSOLogin();
1226 // If a user was found via SSO, then use it
1227 if ( $ssoUser !== false )
1228 {
1229 $currentUser = $ssoUser;
1230 $userId = $currentUser->attribute( 'contentobject_id' );
1231
1232 $userInfo = array();
1233 $userInfo[$userId] = array(
1234 'contentobject_id' => $userId,
1235 'login' => $currentUser->attribute( 'login' ),
1236 'email' => $currentUser->attribute( 'email' ),
1237 'password_hash' => $currentUser->attribute( 'password_hash' ),
1238 'password_hash_type' => $currentUser->attribute( 'password_hash_type' )
1239 );
1240 eZSession::setUserID( $userId );
1241 $http->setSessionVariable( 'eZUserLoggedInID', $userId );
1242
1243 eZUser::updateLastVisit( $userId );
1244 eZUser::setCurrentlyLoggedInUser( $currentUser, $userId );
1245 eZHTTPTool::redirect( eZSys::wwwDir() . eZSys::indexFile( false ) . eZSys::requestURI() . eZSys::queryString(), array(), 302 );
1246 eZExecution::cleanExit();
1247 }
1248 }
1249 else
1250 {
1251 eZDebug::writeError( "Undefined ssoHandler class: $className", __METHOD__ );
1252 }
1253 }
1254 }
1255 }
1256
1257 if ( $userId <> $anonymousUserID )
1258 {
1259 $sessionInactivityTimeout = $ini->variable( 'Session', 'ActivityTimeout' );
1260 if ( !isset( $GLOBALS['eZSessionIdleTime'] ) )
1261 {
1262 eZUser::updateLastVisit( $userId );
1263 }
1264 else
1265 {
1266 $sessionIdle = $GLOBALS['eZSessionIdleTime'];
1267 if ( $sessionIdle > $sessionInactivityTimeout )
1268 {
1269 eZUser::updateLastVisit( $userId );
1270 }
1271 }
1272 }
1273
1274 if ( !$currentUser )
1275 {
1276 $currentUser = eZUser::fetch( self::anonymousId() );
1277 eZDebug::writeWarning( 'User not found, returning anonymous' );
1278 }
1279
1280 if ( !$currentUser )
1281 {
1282 $currentUser = new eZUser( array( 'id' => -1, 'login' => 'NoUser' ) );
1283 eZDebug::writeWarning( 'Anonymous user not found, returning NoUser' );
1284 }
1285
1286 $GLOBALS["eZUserGlobalInstance_$id"] = $currentUser;
1287 return $currentUser;
1288 }
1289
1296 public function getUserCache()
1297 {
1298 if ( $this->UserCache === null )
1299 {
1300 $this->setUserCache( self::getUserCacheByUserId( $this->ContentObjectID ) );
1301 }
1302 return $this->UserCache;
1303 }
1304
1310 public function purgeUserCache()
1311 {
1312 $this->UserCache = null;
1313 self::purgeUserCacheByUserId( $this->ContentObjectID );
1314 }
1315
1323 public function setUserCache( array $userCache )
1324 {
1325 $this->UserCache = $userCache;
1326 }
1327
1334 static public function purgeUserCacheByAnonymousId()
1335 {
1336 self::purgeUserCacheByUserId( self::anonymousId() );
1337 }
1338
1345 static public function purgeUserCacheByUserId( $userId )
1346 {
1347 if ( eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ) === 'true' )
1348 {
1349 $cacheFilePath = eZUser::getCacheDir( $userId ). "/user-data-{$userId}.cache.php" ;
1350 eZClusterFileHandler::instance()->fileDelete( $cacheFilePath );
1351 }
1352 }
1353
1361 static public function getUserCacheByAnonymousId()
1362 {
1363 return self::getUserCacheByUserId( self::anonymousId() );
1364 }
1365
1374 static protected function getUserCacheByUserId( $userId )
1375 {
1376 $userCache = null;
1377
1378 if ( eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ) === 'true' )
1379 {
1380 $cacheFilePath = eZUser::getCacheDir( $userId ) . "/user-data-{$userId}.cache.php";
1381 $cacheFile = eZClusterFileHandler::instance( $cacheFilePath );
1382 $userCache = $cacheFile->processCache( array( 'eZUser', 'retrieveUserCacheFromFile' ),
1383 array( 'eZUser', 'generateUserCacheForFile' ),
1384 null,
1385 self::userInfoExpiry(),
1386 $userId );
1387 }
1388
1389 if ( $userCache === null || $userCache instanceof eZClusterFileFailure )
1390 {
1391 $userCache = self::generateUserCacheContent( $userId );
1392 }
1393
1394 return $userCache;
1395 }
1396
1404 static function retrieveUserCacheFromFile( $filePath, $mtime, $userId )
1405 {
1406 $userCache = include( $filePath );
1407
1408 // check that the returned array is not corrupted
1409 if ( is_array( $userCache )
1410 && isset( $userCache['info'] )
1411 && isset( $userCache['info'][$userId] )
1412 && is_numeric( $userCache['info'][$userId]['contentobject_id'] )
1413 && isset( $userCache['groups'] )
1414 && isset( $userCache['roles'] )
1415 && isset( $userCache['role_limitations'] )
1416 && isset( $userCache['access_array'] )
1417 && isset( $userCache['discount_rules'] ) )
1418 {
1419 return $userCache;
1420 }
1421
1422 eZDebug::writeError( 'Cache file ' . $filePath . ' is corrupted, forcing generation.', __METHOD__ );
1423 return new eZClusterFileFailure( 1, 'Cache file ' . $filePath . ' is corrupted, forcing generation.' );
1424 }
1425
1433 private static function generateUserCacheContent( $userId )
1434 {
1435 $cacheData = self::generateUserCacheData( $userId );
1436
1437 if ( $cacheData === null )
1438 {
1439 $cacheData = array( 'info' => array(),
1440 'groups' => array(),
1441 'roles' => array(),
1442 'role_limitations' => array(),
1443 'access_array' => array(),
1444 'discount_rules' => array() );
1445 }
1446
1447 return $cacheData;
1448 }
1449
1457 private static function generateUserCacheData( $userId )
1458 {
1459 $user = eZUser::fetch( $userId );
1460 if ( !$user instanceof eZUser )
1461 {
1462 return null;
1463 }
1464
1465 // user info (session: eZUserInfoCache)
1466 $data['info'][$userId] = array( 'contentobject_id' => $user->attribute( 'contentobject_id' ),
1467 'login' => $user->attribute( 'login' ),
1468 'email' => $user->attribute( 'email' ),
1469 'is_enabled' => $user->isEnabled( false ),
1470 'password_hash' => $user->attribute( 'password_hash' ),
1471 'password_hash_type' => $user->attribute( 'password_hash_type' ) );
1472
1473 // function groups relies on caching. The function generateUserCacheData relies on function groups.
1474 // To avoid an infinitive loop, the code is disabling caching in function generateUserCacheData.
1475 // At the end of this method flag is set to previous value again
1476 $previousCachingState = $user->setCachingEnabled( false );
1477 // user groups list (session: eZUserGroupsCache)
1478 $groups = $user->groups();
1479 $data['groups'] = $groups;
1480
1481 // role list (session: eZRoleIDList)
1482 $groups[] = $userId;
1483 $data['roles'] = eZRole::fetchIDListByUser( $groups );
1484
1485 // role limitation list (session: eZRoleLimitationValueList)
1486 $limitList = $user->limitList();
1487 foreach ( $limitList as $limit )
1488 {
1489 $data['role_limitations'][] = $limit['limit_value'];
1490 }
1491
1492 // access array (session: AccessArray)
1493 $data['access_array'] = $user->generateAccessArray();
1494
1495 // discount rules (session: eZUserDiscountRules<userId>)
1496 $data['discount_rules'] = eZUserDiscountRule::generateIDListByUserID( $userId );
1497
1498 $user->setCachingEnabled( $previousCachingState );
1499
1500 return $data;
1501 }
1502
1510 static function generateUserCacheForFile( $filePath, $userId )
1511 {
1512 $cacheData = self::generateUserCacheData( $userId );
1513
1514 if ( $cacheData !== null )
1515 {
1516 $cacheData = array( 'content' => $cacheData,
1517 'scope' => 'user-info-cache',
1518 'datatype' => 'php',
1519 'store' => true );
1520 }
1521
1522 return $cacheData;
1523 }
1524
1529 static function updateLastVisit( $userID, $updateLoginCount = false )
1530 {
1531 if ( isset( $GLOBALS['eZUserUpdatedLastVisit'] ) )
1532 return;
1533 $db = eZDB::instance();
1534 $userID = (int) $userID;
1535 $userVisitArray = $db->arrayQuery( "SELECT 1 FROM ezuservisit WHERE user_id=$userID" );
1536 $time = time();
1537
1538 if ( isset( $userVisitArray[0] ) )
1539 {
1540 $loginCountSQL = $updateLoginCount ? ', login_count=login_count+1' : '';
1541 $db->query( "UPDATE ezuservisit SET last_visit_timestamp=ABS(current_visit_timestamp), current_visit_timestamp=$time$loginCountSQL WHERE user_id=$userID" );
1542 }
1543 else
1544 {
1545 $intialLoginCount = $updateLoginCount ? 1 : 0;
1546 $db->query( "INSERT INTO ezuservisit ( current_visit_timestamp, last_visit_timestamp, user_id, login_count ) VALUES ( $time, $time, $userID, $intialLoginCount )" );
1547 }
1548 $GLOBALS['eZUserUpdatedLastVisit'] = true;
1549 }
1550
1554 function lastVisit()
1555 {
1556 $db = eZDB::instance();
1557
1558 $userVisitArray = $db->arrayQuery( "SELECT last_visit_timestamp FROM ezuservisit WHERE user_id=$this->ContentObjectID" );
1559 if ( isset( $userVisitArray[0] ) )
1560 {
1561 return $userVisitArray[0]['last_visit_timestamp'];
1562 }
1563 else
1564 {
1565 return time();
1566 }
1567 }
1568
1575 function loginCount()
1576 {
1577 $db = eZDB::instance();
1578 $userVisitArray = $db->arrayQuery( "SELECT login_count FROM ezuservisit WHERE user_id=$this->ContentObjectID" );
1579 if ( isset( $userVisitArray[0] ) )
1580 {
1581 return $userVisitArray[0]['login_count'];
1582 }
1583 else
1584 {
1585 return 0;
1586 }
1587 }
1588
1594 static function setFailedLoginAttempts( $userID, $value = false, $setByForce = false )
1595 {
1596 $trustedUser = eZUser::isTrusted();
1597 // If user is trusted we should stop processing
1598 if ( $trustedUser and !$setByForce )
1599 return true;
1600
1601 $maxNumberOfFailedLogin = eZUser::maxNumberOfFailedLogin();
1602
1603 if ( $maxNumberOfFailedLogin == '0' and !$setByForce )
1604 return true;
1605
1606 $userID = (int) $userID;
1607 $userObject = eZUser::fetch( $userID );
1608 if ( !$userObject )
1609 return true;
1610
1611 $isEnabled = $userObject->isEnabled();
1612 // If current user is disabled we should not continue
1613 if ( !$isEnabled and !$setByForce )
1614 return true;
1615
1616 $db = eZDB::instance();
1617 $db->begin();
1618
1619 $userVisitArray = $db->arrayQuery( "SELECT 1 FROM ezuservisit WHERE user_id=$userID" );
1620
1621 if ( isset( $userVisitArray[0] ) )
1622 {
1623 if ( $value === false )
1624 {
1625 $failedLoginAttempts = $userObject->failedLoginAttempts();
1626 $failedLoginAttempts += 1;
1627 }
1628 else
1629 $failedLoginAttempts = (int) $value;
1630
1631 $db->query( "UPDATE ezuservisit SET failed_login_attempts=$failedLoginAttempts WHERE user_id=$userID" );
1632 }
1633 else
1634 {
1635 if ( $value === false )
1636 {
1637 $failedLoginAttempts = 1;
1638 }
1639 else
1640 $failedLoginAttempts = (int) $value;
1641
1642 $db->query( "INSERT INTO ezuservisit ( failed_login_attempts, user_id ) VALUES ( $failedLoginAttempts, $userID )" );
1643 }
1644 $db->commit();
1645
1646 eZContentCacheManager::clearContentCacheIfNeeded( $userID );
1647 eZContentCacheManager::generateObjectViewCache( $userID );
1648 }
1649
1653 function failedLoginAttempts()
1654 {
1655 return eZUser::failedLoginAttemptsByUserID( $this->attribute( 'contentobject_id' ) );
1656 }
1657
1661 static function failedLoginAttemptsByUserID( $userID )
1662 {
1663 $db = eZDB::instance();
1664 $contentObjectID = (int) $userID;
1665
1666 $userVisitArray = $db->arrayQuery( "SELECT failed_login_attempts FROM ezuservisit WHERE user_id=$contentObjectID" );
1667
1668 $failedLoginAttempts = isset( $userVisitArray[0] ) ? $userVisitArray[0]['failed_login_attempts'] : 0;
1669 return $failedLoginAttempts;
1670 }
1671
1675 function isLocked()
1676 {
1677 $userID = $this->attribute( 'contentobject_id' );
1678 $isNotLocked = eZUser::isEnabledAfterFailedLogin( $userID, true );
1679 return !$isNotLocked;
1680 }
1681
1685 function isEnabled( $useCache = true )
1686 {
1687 if ( isset( $this->UserCache['info'][$this->ContentObjectID]['is_enabled'] ) && $useCache )
1688 {
1689 return $this->UserCache['info'][$this->ContentObjectID]['is_enabled'];
1690 }
1691
1692 $setting = eZUserSetting::fetch( $this->attribute( 'contentobject_id' ) );
1693 if ( $setting and !$setting->attribute( 'is_enabled' ) )
1694 {
1695 return false;
1696 }
1697 return true;
1698 }
1699
1703 function isAnonymous()
1704 {
1705 if ( $this->attribute( 'contentobject_id' ) != self::anonymousId() )
1706 {
1707 return false;
1708 }
1709 return true;
1710 }
1711
1716 static function currentUser()
1717 {
1718 $user = self::instance();
1719 if ( $user->isAnonymous() || $user->isEnabled() )
1720 {
1721 return $user;
1722 }
1723 self::logoutCurrent();
1724 return self::instance();
1725 }
1726
1731 static function currentUserID()
1732 {
1733 return self::currentUser()->attribute( 'contentobject_id' );
1734 }
1735
1741 static function authenticateHash( $user, $password, $site, $type, $hash )
1742 {
1743 if ( $user == '' || $password == '' || $type == self::PASSWORD_HASH_EMPTY )
1744 {
1745 return false;
1746 }
1747
1748 return eZUser::createHash( $user, $password, $site, $type, $hash ) === (string) $hash;
1749 }
1750
1755 static function passwordCharacterTable()
1756 {
1757 if ( !empty( $GLOBALS['eZUserPasswordCharacterTable'] ) )
1758 {
1759 return $GLOBALS['eZUserPasswordCharacterTable'];
1760 }
1761 $table = array_merge( range( 'a', 'z' ), range( 'A', 'Z' ), range( 0, 9 ) );
1762
1763 $ini = eZINI::instance();
1764 if ( $ini->variable( 'UserSettings', 'UseSpecialCharacters' ) == 'true' )
1765 {
1766 $specialCharacters = '!#%&{[]}+?;:*';
1767 $table = array_merge( $table, preg_split( '//', $specialCharacters, -1, PREG_SPLIT_NO_EMPTY ) );
1768 }
1769 // Remove some characters that are too similar visually
1770 $table = array_diff( $table, array( 'I', 'l', 'o', 'O', '0' ) );
1771 $tableTmp = $table;
1772 $table = array();
1773 foreach ( $tableTmp as $item )
1774 {
1775 $table[] = $item;
1776 }
1777
1778 return $GLOBALS['eZUserPasswordCharacterTable'] = $table;
1779 }
1780
1788 static function isUserObject( $contentObject )
1789 {
1790 if ( !$contentObject )
1791 {
1792 return false;
1793 }
1794
1795 eZDataType::loadAndRegisterType( 'ezuser' );
1796
1797 $contentClass = $contentObject->attribute( 'content_class' );
1798 $classAttributeList = $contentClass->fetchAttributes();
1799 foreach( $classAttributeList as $classAttribute )
1800 {
1801 if ( $classAttribute->attribute( 'data_type_string' ) == eZUserType::DATA_TYPE_STRING )
1802 return true;
1803 }
1804
1805 return false;
1806 }
1807
1816 static function createPassword( $passwordLength, $seed = false )
1817 {
1818 $chars = 0;
1819 $password = '';
1820 if ( $passwordLength < 1 )
1821 $passwordLength = 1;
1822 $decimal = 0;
1823 while ( $chars < $passwordLength )
1824 {
1825 if ( $seed == false )
1826 $seed = time() . ":" . mt_rand();
1827 $text = md5( $seed );
1828 $characterTable = eZUser::passwordCharacterTable();
1829 $tableCount = count( $characterTable );
1830 for ( $i = 0; ( $chars < $passwordLength ) and $i < 32; ++$chars, $i += 2 )
1831 {
1832 $decimal += hexdec( substr( $text, $i, 2 ) );
1833 $index = ( $decimal % $tableCount );
1834 $character = $characterTable[$index];
1835 $password .= $character;
1836 }
1837 $seed = false;
1838 }
1839 return $password;
1840 }
1841
1846 static function createHash( $user, $password, $site, $type, $hash = false )
1847 {
1848 $user = self::trimAuthString( $user );
1849 $password = self::trimAuthString( $password );
1850
1851 $str = '';
1852 if ( $type == self::PASSWORD_HASH_MD5_PASSWORD )
1853 {
1854 $str = md5( $password );
1855 }
1856 else if ( $type == self::PASSWORD_HASH_MD5_USER )
1857 {
1858 $str = md5( "$user\n$password" );
1859 }
1860 else if ( $type == self::PASSWORD_HASH_MD5_SITE )
1861 {
1862 $str = md5( "$user\n$password\n$site" );
1863 }
1864 else if ( $type == self::PASSWORD_HASH_MYSQL )
1865 {
1866 $db = eZDB::instance();
1867 $hash = $db->escapeString( $password );
1868
1869 $str = $db->arrayQuery( "SELECT PASSWORD( '$hash' )" );
1870 $hashes = array_values( $str[0] );
1871 $str = $hashes[0];
1872 }
1873 else if ( $type == self::PASSWORD_HASH_PLAINTEXT )
1874 {
1875 $str = $password;
1876 }
1877 else if ( ( $type == self::PASSWORD_HASH_BCRYPT ||
1878 $type == self::PASSWORD_HASH_PHP_DEFAULT ) &&
1879 $hash )
1880 {
1881 if ( password_verify( $password, $hash ) )
1882 {
1883 return $hash;
1884 }
1885
1886 return false;
1887 }
1888 else if ( $type == self::PASSWORD_HASH_BCRYPT )
1889 {
1890 $str = password_hash( $password, PASSWORD_BCRYPT );
1891 }
1892 else if ( $type == self::PASSWORD_HASH_PHP_DEFAULT )
1893 {
1894 $str = password_hash( $password, PASSWORD_DEFAULT );
1895 }
1896 else
1897 {
1898 if ( $type == self::PASSWORD_HASH_EMPTY )
1899 {
1900 eZDebug::writeError( "Cannot create hash of hash type 0 (PASSWORD_HASH_EMPTY)." );
1901 }
1902 else
1903 {
1904 eZDebug::writeError( "Password hash type ID '$type' is not recognized." );
1905 }
1906
1907 return false;
1908 }
1909
1910 eZDebugSetting::writeDebug( 'kernel-user', $str, "ezuser($type)" );
1911 return $str;
1912 }
1913
1922 private static function trimAuthString( $string )
1923 {
1924 if ( strlen( $string ) <= self::AUTH_STRING_MAX_LENGTH )
1925 {
1926 return $string;
1927 }
1928 else
1929 {
1930 return substr( $string, 0, self::AUTH_STRING_MAX_LENGTH );
1931 }
1932 }
1933
1947 function hasAccessTo( $module, $function = false )
1948 {
1949 $accessArray = $this->accessArray();
1950
1951 $functionArray = array();
1952 if ( isset( $accessArray['*']['*'] ) )
1953 {
1954 $functionArray = $accessArray['*']['*'];
1955 }
1956 if ( isset( $accessArray[$module] ) )
1957 {
1958 if ( isset( $accessArray[$module]['*'] ) )
1959 {
1960 $functionArray = array_merge_recursive( $functionArray, $accessArray[$module]['*'] );
1961 }
1962 if ( $function and isset( $accessArray[$module][$function] ) and $function != '*' )
1963 {
1964 $functionArray = array_merge_recursive( $functionArray, $accessArray[$module][$function] );
1965 }
1966 }
1967
1968 if ( !$functionArray )
1969 {
1970 return array( 'accessWord' => 'no',
1971 'accessList' => array( 'FunctionRequired' => array ( 'Module' => $module,
1972 'Function' => $function,
1973 'ClassID' => '',
1974 'MainNodeID' => '' ),
1975 'PolicyList' => array() )
1976 );
1977 }
1978
1979 if ( isset( $functionArray['*'] ) &&
1980 ( $functionArray['*'] == '*' || in_array( '*', $functionArray['*'] ) ) )
1981 {
1982 return array( 'accessWord' => 'yes' );
1983 }
1984
1985 return array( 'accessWord' => 'limited', 'policies' => $functionArray );
1986 }
1987
1995 function accessArray()
1996 {
1997 if ( !isset( $this->AccessArray ) )
1998 {
1999 if ( eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ) === 'true' )
2000 {
2001 $userCache = $this->getUserCache();
2002 $this->AccessArray = $userCache['access_array'];
2003 }
2004 else
2005 {
2006 // if role caching is disabled then generate access array on-the-fly.
2007 $this->AccessArray = $this->generateAccessArray();
2008 }
2009 }
2010 return $this->AccessArray;
2011 }
2012
2020 function generateAccessArray()
2021 {
2022 $idList = $this->groups();
2023 $idList[] = $this->attribute( 'contentobject_id' );
2024
2025 return eZRole::accessArrayByUserID( $idList );
2026 }
2027
2033 static protected function userInfoExpiry()
2034 {
2035 /* Figure out when the last update was done */
2036 $handler = eZExpiryHandler::instance();
2037 if ( $handler->hasTimestamp( 'user-info-cache' ) )
2038 {
2039 $expiredTimestamp = $handler->timestamp( 'user-info-cache' );
2040 }
2041 else
2042 {
2043 $expiredTimestamp = time();
2044 $handler->setTimestamp( 'user-info-cache', $expiredTimestamp );
2045 }
2046
2047 return $expiredTimestamp;
2048 }
2049
2050 /*
2051 Returns list of sections which are allowed to assign to the given content object by the user.
2052 */
2053 function canAssignToObjectSectionList( $contentObject )
2054 {
2055 $access = $this->hasAccessTo( 'section', 'assign' );
2056
2057 if ( $access['accessWord'] == 'yes' )
2058 {
2059 return array( '*' );
2060 }
2061 else if ( $access['accessWord'] == 'limited' )
2062 {
2063 $userID = $this->attribute( 'contentobject_id' );
2064 $classID = $contentObject->attribute( 'contentclass_id' );
2065 $ownerID = $contentObject->attribute( 'owner_id' );
2066 $sectionID = $contentObject->attribute( 'section_id' );
2067
2068 $allowedSectionIDList = array();
2069 foreach ( $access['policies'] as $policy )
2070 {
2071 if ( ( isset( $policy['Class'] ) and !in_array( $classID, $policy['Class'] ) ) or
2072 ( isset( $policy['Owner'] ) and in_array( 1, $policy['Owner'] ) and $userID != $ownerID ) or
2073 ( isset( $policy['Section'] ) and !in_array( $sectionID, $policy['Section'] ) ) )
2074 {
2075 continue;
2076 }
2077 if ( isset( $policy['NewSection'] ) && !empty( $policy['NewSection'] ) )
2078 {
2079 $allowedSectionIDList = array_merge( $allowedSectionIDList, $policy['NewSection'] );
2080 }
2081 else
2082 {
2083 return array( '*' );
2084 }
2085 }
2086 $allowedSectionIDList = array_unique( $allowedSectionIDList );
2087 return $allowedSectionIDList;
2088 }
2089 return array();
2090 }
2091
2092 /*
2093 Checks whether user can assign the section to the given content object or not.
2094 */
2095 function canAssignSectionToObject( $checkSectionID, $contentObject )
2096 {
2097 $access = $this->hasAccessTo( 'section', 'assign' );
2098
2099 if ( $access['accessWord'] == 'yes' )
2100 {
2101 return true;
2102 }
2103 else if ( $access['accessWord'] == 'limited' )
2104 {
2105 $userID = $this->attribute( 'contentobject_id' );
2106 $classID = $contentObject->attribute( 'contentclass_id' );
2107 $ownerID = $contentObject->attribute( 'owner_id' );
2108 $sectionID = $contentObject->attribute( 'section_id' );
2109 $nodePath = $contentObject->mainNode()->PathString;
2110
2111 foreach ( $access['policies'] as $policy )
2112 {
2113 if ( ( isset( $policy['Class'] ) and !in_array( $classID, $policy['Class'] ) ) or
2114 ( isset( $policy['Owner'] ) and in_array( 1, $policy['Owner'] ) and $userID != $ownerID ) or
2115 ( isset( $policy['Section'] ) and !in_array( $sectionID, $policy['Section'] ) ) )
2116 {
2117 continue;
2118 }
2119 if ( isset( $policy['User_Subtree'] ) )
2120 {
2121 $subtreeLimitationResult = false;
2122 foreach ( $policy['User_Subtree'] as $path )
2123 {
2124 if ( strpos( $nodePath, $path ) !== false )
2125 {
2126 $subtreeLimitationResult = true;
2127 }
2128 }
2129 // If a subtree limitation exists and none of the path corresponds then the user have not enough rights.
2130 if ( !$subtreeLimitationResult )
2131 {
2132 continue;
2133 }
2134 }
2135 if ( isset( $policy['NewSection'] ) )
2136 {
2137 if ( is_array( $policy['NewSection'] ) and in_array( $checkSectionID, $policy['NewSection'] ) )
2138 {
2139 return true;
2140 }
2141 }
2142 else
2143 {
2144 return true;
2145 }
2146 }
2147 }
2148 return false;
2149 }
2150
2151 /*
2152 Checks whether user has privileges to assign the section or not at all.
2153 */
2154 function canAssignSection( $checkSectionID )
2155 {
2156 $access = $this->hasAccessTo( 'section', 'assign' );
2157
2158 if ( $access['accessWord'] == 'yes' )
2159 {
2160 return true;
2161 }
2162 else if ( $access['accessWord'] == 'limited' )
2163 {
2164 foreach ( $access['policies'] as $policy )
2165 {
2166 if ( isset( $policy['NewSection'] ) )
2167 {
2168 if ( in_array( $checkSectionID, $policy['NewSection'] ) )
2169 {
2170 return true;
2171 }
2172 }
2173 else
2174 {
2175 return true;
2176 }
2177 }
2178 }
2179 return false;
2180 }
2181
2182 /*
2183 Returns list of sections allowed to assign for the user.
2184 */
2185 function canAssignSectionList()
2186 {
2187 $access = $this->hasAccessTo( 'section', 'assign' );
2188
2189 if ( $access['accessWord'] == 'yes' )
2190 {
2191 return array( '*' );
2192 }
2193 else if ( $access['accessWord'] == 'limited' )
2194 {
2195 $allowedSectionIDList = array();
2196 foreach ( $access['policies'] as $policy )
2197 {
2198 if ( isset( $policy['NewSection'] ) )
2199 {
2200 if ( is_array( $policy['NewSection'] ) && !empty( $policy['NewSection'] ) )
2201 {
2202 $allowedSectionIDList = array_merge( $allowedSectionIDList, $policy['NewSection'] );
2203 }
2204 }
2205 else
2206 {
2207 return array( '*' );
2208 }
2209 }
2210 $allowedSectionIDList = array_unique( $allowedSectionIDList );
2211 return $allowedSectionIDList;
2212 }
2213 return array();
2214 }
2215
2216 /*
2217 Returns list of classes allowed to assign to the given section for the user.
2218 */
2219 function canAssignSectionToClassList( $checkSectionID )
2220 {
2221 $access = $this->hasAccessTo( 'section', 'assign' );
2222
2223 if ( $access['accessWord'] == 'yes' )
2224 {
2225 return array( '*' );
2226 }
2227 else if ( $access['accessWord'] == 'limited' )
2228 {
2229 $allowedClassList = array();
2230 foreach ( $access['policies'] as $policy )
2231 {
2232 if ( !isset( $policy['NewSection'] ) or in_array( $checkSectionID, $policy['NewSection'] ) )
2233 {
2234 if ( isset( $policy['Class'] ) )
2235 {
2236 $allowedClassList = array_merge( $allowedClassList, $policy['Class'] );
2237 }
2238 else
2239 {
2240 return array( '*' );
2241 }
2242 }
2243 }
2244
2245 if ( !empty( $allowedClassList ) )
2246 {
2247 // Now we are trying to fetch classes by collected ids list to return
2248 // class list consisting of existing classes's identifiers only.
2249 $allowedClassList = array_unique( $allowedClassList );
2250 $classList = eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, false, false, null, null, $allowedClassList );
2251 if ( is_array( $classList ) && !empty( $classList ) )
2252 {
2253 $classIdentifierList = array();
2254 foreach( $classList as $class )
2255 {
2256 $classIdentifierList[] = $class['identifier'];
2257 }
2258 return $classIdentifierList;
2259 }
2260 }
2261 }
2262 return array();
2263 }
2264
2265 /*
2266 Evaluates if $this user has access to the view $viewName based on its policy functions and
2267 checks if the assigned to the view functions expression is valid and handles errors if it is not.
2268 Returns true if access is allowed, false if access is denied.
2269 */
2270 function hasAccessToView( $module, $viewName, &$params )
2271 {
2272 $validView = false;
2273 $accessAllowed = false;
2274 if ( $module->singleFunction() )
2275 {
2276 $info = $module->attribute( 'info' );
2277 if ( isset( $info['function'] ) )
2278 {
2279 $validView = true;
2280 if ( isset( $info['function']['functions'] ) && !empty( $info['function']['functions'] ) )
2281 {
2282 $functions = $info['function']['functions'];
2283 }
2284 }
2285 }
2286 else
2287 {
2288 $views = $module->attribute( 'views' );
2289 if ( isset( $views[$viewName] ) )
2290 {
2291 $view = $views[$viewName];
2292 $validView = true;
2293 if ( isset( $view['functions'] ) && !empty( $view['functions'] ) )
2294 {
2295 $functions = $view['functions'];
2296 }
2297 }
2298 }
2299
2300 if ( $validView )
2301 {
2302 if ( isset( $functions ) )
2303 {
2304 if ( is_array( $functions ) )
2305 {
2306 $funcExpression = false;
2307 $accessAllowed = true;
2308 foreach ( $functions as $function )
2309 {
2310 if ( empty( $function ) )
2311 {
2312 $funcExpression = false;
2313 $accessAllowed = false;
2314 break;
2315 }
2316 else if ( is_string( $function ) )
2317 {
2318 if ( $funcExpression )
2319 {
2320 $funcExpression .= ' and ';
2321 }
2322 $funcExpression .= '( ' . $function . ' )';
2323 }
2324 }
2325 }
2326 else if ( is_string( $functions ) )
2327 {
2328 $funcExpression = $functions;
2329 }
2330 else
2331 {
2332 $funcExpression = false;
2333 $accessAllowed = true;
2334 }
2335
2336 if ( $funcExpression )
2337 {
2338 // Validate and evaluate functions expression.
2339 // Lets construct functions's expression ready for evaluating first.
2340 $pS = '/(?<=\b)';
2341 $pE = '(?=\b)/';
2342
2343 $moduleName = $module->attribute( 'name' );
2344 $availableFunctions = $module->attribute( 'available_functions' );
2345 if ( is_array( $availableFunctions ) and
2346 !empty( $availableFunctions ) )
2347 {
2348 $pattern = $pS . '(' . implode( '|', array_keys( $availableFunctions ) ) . ')' . $pE;
2349 $matches = array();
2350 if ( preg_match_all( $pattern, ' ' . $funcExpression . ' ', $matches ) > 0 )
2351 {
2352 $patterns = array();
2353 $replacements = array();
2354 $matches = array_unique( $matches[1] );
2355 foreach ( $matches as $match )
2356 {
2357 if ( !isset( $replacements[$match] ) )
2358 {
2359 $accessResult = $this->hasAccessTo( $moduleName, $match );
2360 if ( $accessResult['accessWord'] == 'no' )
2361 {
2362 $replacements[$match] = 'false';
2363 $params['accessList'] = $accessResult['accessList'];
2364 }
2365 else
2366 {
2367 $replacements[$match] = 'true';
2368 if ( $accessResult['accessWord'] == 'limited' )
2369 {
2370 $params['Limitation'] = $accessResult['policies'];
2371 $GLOBALS['ezpolicylimitation_list'][$this->ContentObjectID][$moduleName][$match] = $params['Limitation'];
2372 }
2373 }
2374 $patterns[$match] = $pS . $match . $pE;
2375 }
2376 }
2377 $funcExpression = preg_replace( $patterns, $replacements, ' ' . $funcExpression . ' ' );
2378 }
2379 }
2380 $funcExpressionForEval = $funcExpression;
2381
2382 // continue to validate expression
2383 $words = array();
2384 $words[] = $pS . 'and' . $pE;
2385 $words[] = $pS . 'or' . $pE;
2386 $words[] = $pS . 'true' . $pE;
2387 $words[] = $pS . 'false' . $pE;
2388 $pS = '/(?<=[^&|])';
2389 $pE = '(?=[^&|])/';
2390 $words[] = $pS . '\|\|' . $pE;
2391 $words[] = $pS . '&&' . $pE;
2392 $words[] = '/[\‍(\‍)]/';
2393
2394 $replacement = '';
2395 $funcExpression = preg_replace( $words, $replacement, ' ' . $funcExpression . ' ' );
2396
2397 $funcExpression = trim( $funcExpression );
2398
2399 if ( empty( $funcExpression ) )
2400 {
2401 // if expression is valid then evaluate value of the $functionsToEvaluate string
2402 ob_start();
2403 $ret = eval( "\$accessAllowed = ( bool ) ( $funcExpressionForEval );" );
2404 $buffer = ob_get_contents();
2405 ob_end_clean();
2406
2407 // if we get any error while evaluating then set result to false
2408 if ( !empty( $buffer ) or $ret === false )
2409 {
2410 eZDebug::writeError( "There was an error while evaluating the policy functions value of the '$moduleName/$viewName' view. " .
2411 "Please check the '$moduleName/module.php' file." );
2412 $accessAllowed = false;
2413 }
2414 }
2415 else
2416 {
2417 eZDebug::writeError( "There is a mistake in the functions array data of the '$moduleName/$viewName' view. " .
2418 "Please check the '$moduleName/module.php' file." );
2419 $accessAllowed = false;
2420 }
2421 }
2422 }
2423 else
2424 {
2425 $moduleName = $module->attribute( 'name' );
2426 $accessResult = $this->hasAccessTo( $moduleName );
2427 if ( $accessResult['accessWord'] == 'no' )
2428 {
2429 $params['accessList'] = $accessResult['accessList'];
2430 $accessAllowed = false;
2431 }
2432 else
2433 {
2434 $accessAllowed = true;
2435 if ( $accessResult['accessWord'] == 'limited' )
2436 {
2437 $params['Limitation'] = $accessResult['policies'];
2438 $GLOBALS['ezpolicylimitation_list'][$this->ContentObjectID][$moduleName]['*'] = $params['Limitation'];
2439 }
2440 }
2441 }
2442 }
2443
2444 return $accessAllowed;
2445 }
2446
2450 function roles()
2451 {
2452 $groups = $this->attribute( 'groups' );
2453 $groups[] = $this->attribute( 'contentobject_id' );
2454 return eZRole::fetchByUser( $groups );
2455 }
2456
2460 function roleIDList()
2461 {
2462 if ( eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ) === 'true' )
2463 {
2464 $userCache = $this->getUserCache();
2465 return $userCache['roles'];
2466 }
2467
2468 $groups = $this->attribute( 'groups' );
2469 $groups[] = $this->attribute( 'contentobject_id' );
2470 return eZRole::fetchIDListByUser( $groups );
2471 }
2472
2476 function limitList( $useGroupsCache = true )
2477 {
2478 if ( $useGroupsCache )
2479 $groups = $this->groups();
2480 else
2481 $groups = $this->generateGroupIdList();
2482 $groups[] = $this->attribute( 'contentobject_id' );
2483 $groups = implode( ', ', $groups );
2484
2485 $db = eZDB::instance();
2486
2487 $limitationsArray = $db->arrayQuery( "SELECT DISTINCT limit_identifier, limit_value
2488 FROM ezuser_role
2489 WHERE contentobject_id IN ( $groups )" );
2490
2491 return $limitationsArray;
2492 }
2493
2497 function limitValueList()
2498 {
2499 if ( eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ) === 'true' )
2500 {
2501 $userCache = $this->getUserCache();
2502 return $userCache['role_limitations'];
2503 }
2504
2505 $limitValueList = array();
2506 $limitList = $this->limitList();
2507 foreach ( $limitList as $limit )
2508 {
2509 $limitValueList[] = $limit['limit_value'];
2510 }
2511
2512 return $limitValueList;
2513 }
2514
2515 function contentObject()
2516 {
2517 if ( isset( $this->ContentObjectID ) and $this->ContentObjectID )
2518 {
2519 return eZContentObject::fetch( $this->ContentObjectID );
2520 }
2521 return null;
2522 }
2523
2529 public function accountKey()
2530 {
2531 return eZUserAccountKey::fetchByUserID( $this->ContentObjectID );
2532 }
2533
2539 public function isLoggedIn()
2540 {
2541 eZDebug::writeStrict( "Method " . __METHOD__ . " has been deprecated in 5.1. Use isRegistered() / isUserLoggedIn() instead.", "Deprecation" );
2542 return $this->isRegistered();
2543 }
2544
2548 public function isRegistered()
2549 {
2550 return $this->ContentObjectID != self::anonymousId() && $this->ContentObjectID != -1;
2551 }
2552
2558 static public function isCurrentUserRegistered()
2559 {
2560 return self::currentUser()->isRegistered();
2561 }
2562
2566 function groups( $asObject = false )
2567 {
2568 if ( $asObject == true )
2569 {
2570 if ( !isset( $this->GroupsAsObjects ) )
2571 {
2572 $this->GroupsAsObjects = array();
2573
2574 foreach ( $this->groups() as $group )
2575 {
2576 $this->GroupsAsObjects[] = new eZContentObject( $group );
2577 }
2578 }
2579
2580 return $this->GroupsAsObjects;
2581 }
2582 else
2583 {
2584 if ( !isset( $this->Groups ) )
2585 {
2586 $this->fetchUserCacheIfNeeded();
2587 if ( !isset($this->UserCache['groups']) )
2588 {
2589 $this->UserCache['groups'] = $this->generateGroupIdList();
2590 }
2591
2592 $this->Groups = $this->UserCache['groups'];
2593 }
2594
2595 return $this->Groups;
2596 }
2597 }
2598
2605 protected function generateGroupIdList()
2606 {
2607 $db = eZDB::instance();
2608 $userID = $this->ContentObjectID;
2609 $userGroups = $db->arrayQuery( "SELECT c.contentobject_id as id,c.path_string
2610 FROM ezcontentobject_tree b,
2611 ezcontentobject_tree c
2612 WHERE b.contentobject_id='$userID' AND
2613 b.parent_node_id = c.node_id
2614 ORDER BY c.contentobject_id ");
2615 $pathArray = array();
2616 $userGroupArray = array();
2617 foreach ( $userGroups as $group )
2618 {
2619 $pathItems = explode( '/', $group["path_string"] );
2620 array_pop( $pathItems );
2621 array_pop( $pathItems );
2622 foreach ( $pathItems as $pathItem )
2623 {
2624 if ( $pathItem != '' && $pathItem > 1 )
2625 $pathArray[] = $pathItem;
2626 }
2627 $userGroupArray[] = $group['id'];
2628 }
2629
2630 if ( !empty( $pathArray ) )
2631 {
2632 $pathArray = array_unique ($pathArray);
2633 $extraGroups = $db->arrayQuery( "SELECT c.contentobject_id as id
2634 FROM ezcontentobject_tree c,
2635 ezcontentobject d
2636 WHERE c.node_id in ( " . implode( ', ', $pathArray ) . " ) AND
2637 d.id = c.contentobject_id
2638 ORDER BY c.contentobject_id ");
2639 foreach ( $extraGroups as $group )
2640 {
2641 $userGroupArray[] = $group['id'];
2642 }
2643 }
2644 return $userGroupArray;
2645 }
2646
2653 function checkUser( &$siteBasics, $uri )
2654 {
2655 $http = eZHTTPTool::instance();
2656 $check = array( "module" => "user",
2657 "function" => "login" );
2658 if ( eZSession::issetkey( 'eZUserLoggedInID', false ) &&
2659 $http->sessionVariable( "eZUserLoggedInID" ) != '' &&
2660 $http->sessionVariable( "eZUserLoggedInID" ) != self::anonymousId() )
2661 {
2662 $currentUser = eZUser::currentUser();
2663 if ( !$currentUser->isEnabled() )
2664 {
2665 eZUser::logoutCurrent();
2666 $currentUser = eZUser::currentUser();
2667 }
2668 else
2669 {
2670 return null;
2671 }
2672 }
2673
2674 $ini = eZINI::instance();
2675 $moduleName = $uri->element();
2676 $viewName = $uri->element( 1 );
2677 $anonymousAccessList = $ini->variable( "SiteAccessSettings", "AnonymousAccessList" );
2678 foreach ( $anonymousAccessList as $anonymousAccess )
2679 {
2680 $elements = explode( '/', $anonymousAccess );
2681 if ( !isset( $elements[1] ) )
2682 {
2683 if ( $moduleName == $elements[0] )
2684 {
2685 return null;
2686 }
2687 }
2688 else
2689 {
2690 if ( $moduleName == $elements[0] and
2691 $viewName == $elements[1] )
2692 {
2693 return null;
2694 }
2695 }
2696 }
2697
2698 return $check;
2699 }
2700
2707 function preCollectUserInfo()
2708 {
2709 return array( 'module' => 'user', 'function' => 'login' );
2710 }
2711
2721 function postCollectUserInfo()
2722 {
2723 return true;
2724 }
2725
2731 function loginURI()
2732 {
2733 return false;
2734 }
2735
2741 function forceLogin()
2742 {
2743 return false;
2744 }
2745
2753 static function getCacheDir( $userId = 0 )
2754 {
2755 $dir = eZSys::cacheDirectory() . '/user-info' . eZDir::createMultilevelPath( $userId, 5 );
2756
2757 if ( !is_dir( $dir ) )
2758 {
2759 eZDir::mkdir( $dir, false, true );
2760 }
2761 return $dir;
2762 }
2763
2767 static function cleanupCache()
2768 {
2769 $handler = eZExpiryHandler::instance();
2770 $handler->setTimestamp( 'user-info-cache', time() );
2771 $handler->store();
2772 }
2773
2774 static function fetchUserClassList( $asObject = false, $fields = false )
2775 {
2776 // Get names of user classes
2777 if ( !$asObject and
2778 is_array( $fields ) and
2779 !empty( $fields ) )
2780 {
2781 $fieldsFilter = '';
2782 $i = 0;
2783 foreach ( $fields as $fieldName )
2784 {
2785 if ( $i > 0 )
2786 $fieldsFilter .= ', ';
2787 $fieldsFilter .= 'ezcontentclass.' . $fieldName;
2788 $i++;
2789 }
2790 }
2791 else
2792 {
2793 $fieldsFilter = 'ezcontentclass.*';
2794 }
2795 $db = eZDB::instance();
2796 $userClasses = $db->arrayQuery( "SELECT $fieldsFilter
2797 FROM ezcontentclass, ezcontentclass_attribute
2798 WHERE ezcontentclass.id = ezcontentclass_attribute.contentclass_id AND
2799 ezcontentclass.version = " . eZContentClass::VERSION_STATUS_DEFINED ." AND
2800 ezcontentclass_attribute.version = 0 AND
2801 ezcontentclass_attribute.data_type_string = 'ezuser'" );
2802
2803 return eZPersistentObject::handleRows( $userClasses, "eZContentClass", $asObject );
2804 }
2805
2806 static function fetchUserClassNames()
2807 {
2808 $userClassNames = array();
2809 $userClasses = eZUser::fetchUserClassList( false, array( 'identifier' ) );
2810 foreach ( $userClasses as $class )
2811 {
2812 $userClassNames[] = $class[ 'identifier' ];
2813 }
2814 return $userClassNames;
2815 }
2816
2817 static function fetchUserGroupClassNames()
2818 {
2819 // Get names of user classes
2820 $userClassNames = array();
2821 $userClasses = eZUser::fetchUserClassList( false, array( 'identifier' ) );
2822 foreach ( $userClasses as $class )
2823 {
2824 $userClassNames[] = $class[ 'identifier' ];
2825 }
2826
2827 // Get names of all allowed content-classes for the Users subtree
2828 $contentIni = eZINI::instance( "content.ini" );
2829 $userGroupClassNames = array();
2830 if ( $contentIni->hasVariable( 'ClassGroupIDs', 'Users' ) and
2831 is_numeric( $usersClassGroupID = $contentIni->variable( 'ClassGroupIDs', 'Users' ) ) and
2832 count( $usersClassList = eZContentClassClassGroup::fetchClassList( eZContentClass::VERSION_STATUS_DEFINED, $usersClassGroupID ) ) > 0 )
2833 {
2834 foreach ( $usersClassList as $userClass )
2835 {
2836 $userGroupClassNames[] = $userClass->attribute( 'identifier' );
2837 }
2838 }
2839
2840 // Get names of user-group classes
2841 $groupClassNames = array_diff( $userGroupClassNames, $userClassNames );
2842 return $groupClassNames;
2843 }
2844
2850 static function validatePassword( $password )
2851 {
2852 $ini = eZINI::instance();
2853 $minPasswordLength = $ini->variable( 'UserSettings', 'MinPasswordLength' );
2854 if ( $password !== false and
2855 $password !== null and
2856 strlen( $password ) >= (int) $minPasswordLength )
2857 {
2858 return true;
2859 }
2860
2861 return false;
2862 }
2863
2873 static function validateLoginName( $loginName, &$errorText )
2874 {
2875 $ini = eZINI::instance();
2876 $regexList = $ini->variable( 'UserSettings', 'UserNameValidationRegex' );
2877 $errorTextList = $ini->variable( 'UserSettings', 'UserNameValidationErrorText' );
2878 foreach ( $regexList as $key => $regex )
2879 {
2880 if( preg_match( $regex, $loginName) )
2881 {
2882 if ( isset( $errorTextList[$key] ) )
2883 $errorText = $errorTextList[$key];
2884 else
2885 $errorText = $ini->variable( 'UserSettings', 'DefaultUserNameValidationErrorText' );
2886 return false;
2887 }
2888 }
2889 return true;
2890 }
2891
2898 public static function anonymousId()
2899 {
2900 if ( self::$anonymousId === null )
2901 {
2902 $ini = eZINI::instance();
2903 self::$anonymousId = (int)$ini->variable( 'UserSettings', 'AnonymousUserID' );
2904 $GLOBALS['eZUserBuiltins'] = array( self::$anonymousId );
2905 }
2906 return self::$anonymousId;
2907 }
2908
2912 public static function contentClassIDs()
2913 {
2914 $userContentClassIDs = array();
2915
2916 $ini = eZINI::instance( 'content.ini' );
2917 $userDatatypes = $ini->variable( "DataTypeSettings", "UserDataTypes" );
2918
2919 $userContentClassIDs = array();
2920 foreach ( $userDatatypes as $datatypeIdentifier )
2921 {
2922 $userContentClassIDs = array_merge( $userContentClassIDs, eZContentClass::fetchIDListContainingDatatype( $datatypeIdentifier ) );
2923 }
2924
2925 return $userContentClassIDs;
2926 }
2927
2928 public function canLoginToSiteAccess( $access )
2929 {
2930 $siteAccessResult = $this->hasAccessTo( 'user', 'login' );
2931 $hasAccessToSite = false;
2932
2933 if ( $siteAccessResult[ 'accessWord' ] == 'limited' )
2934 {
2935 $siteNameCRC = eZSys::ezcrc32( $access[ 'name' ] );
2936 $policyChecked = false;
2937 foreach ( $siteAccessResult['policies'] as $policy )
2938 {
2939 if ( isset( $policy['SiteAccess'] ) )
2940 {
2941 $policyChecked = true;
2942 if ( in_array( $siteNameCRC, $policy['SiteAccess'] ) )
2943 {
2944 $hasAccessToSite = true;
2945 break;
2946 }
2947 }
2948 }
2949
2950 if ( !$policyChecked )
2951 {
2952 $hasAccessToSite = true;
2953 }
2954 }
2955 else if ( $siteAccessResult[ 'accessWord' ] == 'yes' )
2956 {
2957 $hasAccessToSite = true;
2958 }
2959
2960 return $hasAccessToSite;
2961 }
2962
2966 protected function fetchUserCacheIfNeeded()
2967 {
2968 if ( null === $this->UserCache && true === $this->CachingEnabled && 'true' === eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ))
2969 {
2970 $this->UserCache = $this->getUserCache();
2971 }
2972 }
2973
2981 protected function setCachingEnabled( $cachingEnabled )
2982 {
2983 $previousValue = $this->CachingEnabled;
2984 $this->CachingEnabled = $cachingEnabled;
2985
2986 return $previousValue;
2987 }
2988
2990 public $Login;
2991 public $Email;
2992 public $PasswordHash;
2993 public $PasswordHashType;
2994 public $Groups;
2995 public $OriginalPassword;
2996 public $OriginalPasswordConfirm;
2997 public $AccessArray;
2998 public $ContentObjectID;
2999
3000
3008 protected $UserCache = null;
3009
3016 protected static $userHasLoggedOut = false;
3017
3018 private $CachingEnabled = true;
3019 }
3020
3021 ?>
eZAudit\writeAudit
static writeAudit( $auditName, $auditAttributes=array())
Definition: ezaudit.php:51
eZBasket\cleanupCurrentBasket
static cleanupCurrentBasket( $useSetting=true)
Definition: ezbasket.php:595
eZClusterFileFailure
Definition: ezclusterfilefailure.php:20
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZCollaborationNotificationRule\removeByUserID
static removeByUserID( $userID)
Definition: ezcollaborationnotificationrule.php:91
eZContentCacheManager\clearContentCacheIfNeeded
static clearContentCacheIfNeeded( $objectID, $versionNum=true, $additionalNodeList=false)
Definition: ezcontentcachemanager.php:1062
eZContentCacheManager\generateObjectViewCache
static generateObjectViewCache( $objectID)
Definition: ezcontentcachemanager.php:891
eZContentClassClassGroup\fetchClassList
static fetchClassList( $contentclass_version, $group_id, $asObject=true, $orderByArray=array( 'name'))
Definition: ezcontentclassclassgroup.php:129
eZContentClass\fetchList
static fetchList( $version=eZContentClass::VERSION_STATUS_DEFINED, $asObject=true, $user_id=false, $sorts=null, $fields=null, $classFilter=false, $limit=null)
Definition: ezcontentclass.php:1238
eZContentClass\fetchIDListContainingDatatype
static fetchIDListContainingDatatype( $dataTypeString)
Definition: ezcontentclass.php:1888
eZContentClass\VERSION_STATUS_DEFINED
const VERSION_STATUS_DEFINED
Definition: ezcontentclass.php:22
eZContentObject
Definition: ezcontentobject.php:17
eZContentObject\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: ezcontentobject.php:20
eZContentObject\fetch
static fetch( $id, $asObject=true)
Definition: ezcontentobject.php:885
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDataType\loadAndRegisterType
static loadAndRegisterType( $type)
Definition: ezdatatype.php:1297
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZDebug\isIPInNet
static isIPInNet( $ipaddress, $network, $mask=24)
Definition: ezdebug.php:1057
eZDebug\writeStrict
static writeStrict( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:414
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZExecution\cleanExit
static cleanExit()
Definition: ezexecution.php:100
eZForgotPassword\removeByUserID
static removeByUserID( $userID)
Definition: ezforgotpassword.php:76
eZGeneralDigestUserSettings\removeByUserId
static removeByUserId( $id)
Definition: ezgeneraldigestusersettings.php:146
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
eZMail\validate
static validate( $address)
Definition: ezmail.php:747
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\handleRows
static handleRows( $rows, $class_name, $asObject)
Definition: ezpersistentobject.php:963
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZPreferences\sessionCleanup
static sessionCleanup()
Definition: ezpreferences.php:182
eZRole\fetchIDListByUser
static fetchIDListByUser( $idArray)
Definition: ezrole.php:677
eZRole\fetchByUser
static fetchByUser( $idArray, $recursive=false)
Definition: ezrole.php:500
eZRole\accessArrayByUserID
static accessArrayByUserID( $idArray, $recursive=false)
Definition: ezrole.php:587
eZSubtreeNotificationRule\removeByUserID
static removeByUserID( $userID)
Definition: ezsubtreenotificationrule.php:538
eZSys\requestURI
static requestURI()
Definition: ezsys.php:1262
eZSys\wwwDir
static wwwDir()
Definition: ezsys.php:582
eZSys\clientIP
static clientIP()
Definition: ezsys.php:714
eZSys\queryString
static queryString()
Definition: ezsys.php:607
eZSys\ezcrc32
static ezcrc32( $string)
Definition: ezsys.php:1297
eZSys\indexFile
static indexFile( $withAccessPath=true)
Definition: ezsys.php:618
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
eZUserAccountKey\fetchByUserID
static fetchByUserID( $userID)
Definition: ezuseraccountkey.php:70
eZUserAccountKey\definition
static definition()
Definition: ezuseraccountkey.php:20
eZUserAccountKey\removeByUserID
static removeByUserID( $userID)
Definition: ezuseraccountkey.php:83
eZUserDiscountRule\generateIDListByUserID
static generateIDListByUserID( $userId)
Definition: ezuserdiscountrule.php:135
eZUserSetting\fetch
static fetch( $userID, $asObject=true)
Definition: ezusersetting.php:77
eZUserSetting\removeByUserID
static removeByUserID( $userID)
Definition: ezusersetting.php:98
eZUserSetting\definition
static definition()
Definition: ezusersetting.php:19
eZUserType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezusertype.php:20
eZUser
eZUser handles eZ Publish user accounts
Definition: ezuser.php:19
eZUser\getCacheDir
static getCacheDir( $userId=0)
Definition: ezuser.php:2753
eZUser\NO_SESSION_REGENERATE
const NO_SESSION_REGENERATE
Definition: ezuser.php:63
eZUser\setUserCache
setUserCache(array $userCache)
Definition: ezuser.php:1323
eZUser\passwordHashTypeName
static passwordHashTypeName( $id)
Definition: ezuser.php:135
eZUser\purgeUserCacheByUserId
static purgeUserCacheByUserId( $userId)
Definition: ezuser.php:1345
eZUser\$OriginalPassword
$OriginalPassword
Definition: ezuser.php:2995
eZUser\authenticateHash
static authenticateHash( $user, $password, $site, $type, $hash)
Definition: ezuser.php:1741
eZUser\fetchAnonymousCount
static fetchAnonymousCount()
Definition: ezuser.php:549
eZUser\contentClassIDs
static contentClassIDs()
Definition: ezuser.php:2912
eZUser\preCollectUserInfo
preCollectUserInfo()
Definition: ezuser.php:2707
eZUser\PASSWORD_HASH_MD5_PASSWORD
const PASSWORD_HASH_MD5_PASSWORD
MD5 of password.
Definition: ezuser.php:24
eZUser\trimAuthString
static trimAuthString( $string)
Definition: ezuser.php:1922
eZUser\PASSWORD_HASH_PLAINTEXT
const PASSWORD_HASH_PLAINTEXT
Passwords in plaintext, should not be used for real sites.
Definition: ezuser.php:33
eZUser\authenticationMatch
static authenticationMatch()
Definition: ezuser.php:719
eZUser\canAssignSectionToClassList
canAssignSectionToClassList( $checkSectionID)
Definition: ezuser.php:2219
eZUser\logoutCurrent
static logoutCurrent()
Definition: ezuser.php:1106
eZUser\generateUserCacheForFile
static generateUserCacheForFile( $filePath, $userId)
Definition: ezuser.php:1510
eZUser\loginURI
loginURI()
Definition: ezuser.php:2731
eZUser\$Email
$Email
Definition: ezuser.php:2991
eZUser\$ContentObjectID
$ContentObjectID
Definition: ezuser.php:2998
eZUser\requireUniqueEmail
static requireUniqueEmail()
Definition: ezuser.php:744
eZUser\hasManageLocations
hasManageLocations()
Definition: ezuser.php:226
eZUser\generateUserCacheContent
static generateUserCacheContent( $userId)
Definition: ezuser.php:1433
eZUser\$OriginalPasswordConfirm
$OriginalPasswordConfirm
Definition: ezuser.php:2996
eZUser\fetchLoggedInCount
static fetchLoggedInCount()
Definition: ezuser.php:523
eZUser\hasAccessTo
hasAccessTo( $module, $function=false)
Definition: ezuser.php:1947
eZUser\forceLogin
forceLogin()
Definition: ezuser.php:2741
eZUser\groups
groups( $asObject=false)
Definition: ezuser.php:2566
eZUser\isEnabled
isEnabled( $useCache=true)
Definition: ezuser.php:1685
eZUser\PASSWORD_HASH_MD5_USER
const PASSWORD_HASH_MD5_USER
MD5 of user and password.
Definition: ezuser.php:26
eZUser\userInfoExpiry
static userInfoExpiry()
Definition: ezuser.php:2033
eZUser\setCachingEnabled
setCachingEnabled( $cachingEnabled)
Definition: ezuser.php:2981
eZUser\getUserCacheByAnonymousId
static getUserCacheByAnonymousId()
Definition: ezuser.php:1361
eZUser\$anonymousId
static $anonymousId
Definition: ezuser.php:65
eZUser\getUserCacheByUserId
static getUserCacheByUserId( $userId)
Definition: ezuser.php:1374
eZUser\updateLastVisit
static updateLastVisit( $userID, $updateLoginCount=false)
Definition: ezuser.php:1529
eZUser\setOriginalPassword
setOriginalPassword( $password)
Definition: ezuser.php:274
eZUser\hashType
static hashType()
Definition: ezuser.php:675
eZUser\limitList
limitList( $useGroupsCache=true)
Definition: ezuser.php:2476
eZUser\site
static site()
Definition: ezuser.php:687
eZUser\canAssignSection
canAssignSection( $checkSectionID)
Definition: ezuser.php:2154
eZUser\setInformation
setInformation( $id, $login, $email, $password, $passwordConfirm=false)
Definition: ezuser.php:321
eZUser\isEnabledAfterFailedLogin
static isEnabledAfterFailedLogin( $userID, $ignoreTrusted=false)
Definition: ezuser.php:1014
eZUser\loginCurrent
loginCurrent()
Definition: ezuser.php:1097
eZUser\isRegistered
isRegistered()
Definition: ezuser.php:2548
eZUser\lastVisit
lastVisit()
Definition: ezuser.php:1554
eZUser\$PasswordHash
$PasswordHash
Definition: ezuser.php:2992
eZUser\isTrusted
static isTrusted()
Definition: ezuser.php:980
eZUser\PASSWORD_HASH_MD5_SITE
const PASSWORD_HASH_MD5_SITE
MD5 of site, user and password.
Definition: ezuser.php:28
eZUser\fetchByName
static fetchByName( $login, $asObject=true)
Definition: ezuser.php:361
eZUser\loginFailed
static loginFailed( $userID, $login)
Definition: ezuser.php:799
eZUser\fetchUserGroupClassNames
static fetchUserGroupClassNames()
Definition: ezuser.php:2817
eZUser\canAssignToObjectSectionList
canAssignToObjectSectionList( $contentObject)
Definition: ezuser.php:2053
eZUser\fetchUserClassNames
static fetchUserClassNames()
Definition: ezuser.php:2806
eZUser\fetchLoggedInList
static fetchLoggedInList( $asObject=false, $offset=false, $limit=false, $sortBy=false)
Definition: ezuser.php:413
eZUser\$AccessArray
$AccessArray
Definition: ezuser.php:2997
eZUser\fetchUserCacheIfNeeded
fetchUserCacheIfNeeded()
Definition: ezuser.php:2966
eZUser\loginUser
static loginUser( $login, $password, $authenticationMatch=false)
Definition: ezuser.php:758
eZUser\createPassword
static createPassword( $passwordLength, $seed=false)
Definition: ezuser.php:1816
eZUser\failedLoginAttemptsByUserID
static failedLoginAttemptsByUserID( $userID)
Definition: ezuser.php:1661
eZUser\PASSWORD_HASH_BCRYPT
const PASSWORD_HASH_BCRYPT
Passwords in bcrypt format.
Definition: ezuser.php:35
eZUser\create
static create( $contentObjectID)
Definition: ezuser.php:237
eZUser\retrieveUserCacheFromFile
static retrieveUserCacheFromFile( $filePath, $mtime, $userId)
Definition: ezuser.php:1404
eZUser\setCurrentlyLoggedInUser
static setCurrentlyLoggedInUser( $user, $userID, $flags=0)
Definition: ezuser.php:1054
eZUser\setFailedLoginAttempts
static setFailedLoginAttempts( $userID, $value=false, $setByForce=false)
Definition: ezuser.php:1594
eZUser\cleanupCache
static cleanupCache()
Definition: ezuser.php:2767
eZUser\passwordCharacterTable
static passwordCharacterTable()
Definition: ezuser.php:1755
eZUser\generateGroupIdList
generateGroupIdList()
Definition: ezuser.php:2605
eZUser\isUserObject
static isUserObject( $contentObject)
Definition: ezuser.php:1788
eZUser\$CachingEnabled
$CachingEnabled
Definition: ezuser.php:3018
eZUser\PASSWORD_HASH_EMPTY
const PASSWORD_HASH_EMPTY
No hash, used by external handlers such as LDAP and TextFile.
Definition: ezuser.php:22
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZUser\isUserIPInList
static isUserIPInList( $ipList)
Definition: ezuser.php:937
eZUser\currentUserID
static currentUserID()
Definition: ezuser.php:1731
eZUser\purgeUserCache
purgeUserCache()
Definition: ezuser.php:1310
eZUser\definition
static definition()
Definition: ezuser.php:83
eZUser\removeSessionData
static removeSessionData( $userID)
Definition: ezuser.php:619
eZUser\limitValueList
limitValueList()
Definition: ezuser.php:2497
eZUser\updateLastVisitByLogout
static updateLastVisitByLogout( $userID)
Definition: ezuser.php:1147
eZUser\generateAccessArray
generateAccessArray()
Definition: ezuser.php:2020
eZUser\fetchUnactivated
static fetchUnactivated( $sort=false, $limit=10, $offset=0)
Definition: ezuser.php:387
eZUser\$PasswordHashType
$PasswordHashType
Definition: ezuser.php:2993
eZUser\getUserCache
getUserCache()
Definition: ezuser.php:1296
eZUser\checkUser
checkUser(&$siteBasics, $uri)
Definition: ezuser.php:2653
eZUser\canAssignSectionList
canAssignSectionList()
Definition: ezuser.php:2185
eZUser\fetchByEmail
static fetchByEmail( $email, $asObject=true)
Definition: ezuser.php:369
eZUser\contentObject
contentObject()
Definition: ezuser.php:2515
eZUser\accountKey
accountKey()
Definition: ezuser.php:2529
eZUser\PASSWORD_HASH_PHP_DEFAULT
const PASSWORD_HASH_PHP_DEFAULT
Passwords in PHP default format.
Definition: ezuser.php:37
eZUser\canLoginToSiteAccess
canLoginToSiteAccess( $access)
Definition: ezuser.php:2928
eZUser\_loginUser
static _loginUser( $login, $password, $authenticationMatch=false)
Definition: ezuser.php:825
eZUser\isUserLoggedIn
static isUserLoggedIn( $userID)
Definition: ezuser.php:578
eZUser\maxNumberOfFailedLogin
static maxNumberOfFailedLogin()
Definition: ezuser.php:999
eZUser\fetchContentList
static fetchContentList()
Definition: ezuser.php:657
eZUser\passwordHashTypeID
static passwordHashTypeID( $identifier)
Definition: ezuser.php:177
eZUser\cleanup
static cleanup()
Definition: ezuser.php:1082
eZUser\eZUser
eZUser( $row=array())
Definition: ezuser.php:78
eZUser\accessArray
accessArray()
Definition: ezuser.php:1995
eZUser\hasStoredLogin
hasStoredLogin()
Definition: ezuser.php:289
eZUser\roles
roles()
Definition: ezuser.php:2450
eZUser\$UserCache
$UserCache
Definition: ezuser.php:3008
eZUser\originalPasswordConfirm
originalPasswordConfirm()
Definition: ezuser.php:279
eZUser\PASSWORD_HASH_MYSQL
const PASSWORD_HASH_MYSQL
Definition: ezuser.php:31
eZUser\AUTHENTICATE_ALL
const AUTHENTICATE_ALL
Definition: ezuser.php:55
eZUser\validateLoginName
static validateLoginName( $loginName, &$errorText)
Definition: ezuser.php:2873
eZUser\$Groups
$Groups
Definition: ezuser.php:2994
eZUser\DEFAULT_PASSWORD_HASH
const DEFAULT_PASSWORD_HASH
Definition: ezuser.php:41
eZUser\__construct
__construct( $row=array())
Definition: ezuser.php:67
eZUser\sessionCleanup
sessionCleanup()
Definition: ezuser.php:1073
eZUser\store
store( $fieldFilters=null)
Definition: ezuser.php:254
eZUser\canAssignSectionToObject
canAssignSectionToObject( $checkSectionID, $contentObject)
Definition: ezuser.php:2095
eZUser\failedLoginAttempts
failedLoginAttempts()
Definition: ezuser.php:1653
eZUser\fetchBuiltin
static fetchBuiltin( $id)
Definition: ezuser.php:697
eZUser\loginCount
loginCount()
Definition: ezuser.php:1575
eZUser\clearSessionCache
static clearSessionCache()
Definition: ezuser.php:605
eZUser\AUTHENTICATE_LOGIN
const AUTHENTICATE_LOGIN
Authenticate by matching the login field.
Definition: ezuser.php:51
eZUser\AUTH_STRING_MAX_LENGTH
const AUTH_STRING_MAX_LENGTH
Definition: ezuser.php:48
eZUser\postCollectUserInfo
postCollectUserInfo()
Definition: ezuser.php:2721
eZUser\id
id()
Definition: ezuser.php:711
eZUser\isLoggedIn
isLoggedIn()
Definition: ezuser.php:2539
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
eZUser\isCurrentUserRegistered
static isCurrentUserRegistered()
Definition: ezuser.php:2558
eZUser\instance
static instance( $id=false)
Definition: ezuser.php:1163
eZUser\fetchUserClassList
static fetchUserClassList( $asObject=false, $fields=false)
Definition: ezuser.php:2774
eZUser\anonymousId
static anonymousId()
Definition: ezuser.php:2898
eZUser\isLocked
isLocked()
Definition: ezuser.php:1675
eZUser\hasAccessToView
hasAccessToView( $module, $viewName, &$params)
Definition: ezuser.php:2270
eZUser\purgeUserCacheByAnonymousId
static purgeUserCacheByAnonymousId()
Definition: ezuser.php:1334
eZUser\validatePassword
static validatePassword( $password)
Definition: ezuser.php:2850
eZUser\$userHasLoggedOut
static $userHasLoggedOut
Definition: ezuser.php:3016
eZUser\roleIDList
roleIDList()
Definition: ezuser.php:2460
eZUser\originalPassword
originalPassword()
Definition: ezuser.php:269
eZUser\generateUserCacheData
static generateUserCacheData( $userId)
Definition: ezuser.php:1457
eZUser\isAnonymous
isAnonymous()
Definition: ezuser.php:1703
eZUser\AUTHENTICATE_EMAIL
const AUTHENTICATE_EMAIL
Authenticate by matching the email field.
Definition: ezuser.php:53
eZUser\$Login
$Login
Definition: ezuser.php:2990
eZUser\createHash
static createHash( $user, $password, $site, $type, $hash=false)
Definition: ezuser.php:1846
eZUser\$GroupsAsObjects
$GroupsAsObjects
Definition: ezuser.php:20
eZUser\setOriginalPasswordConfirm
setOriginalPasswordConfirm( $password)
Definition: ezuser.php:284
eZUser\loginSucceeded
static loginSucceeded( $user)
Definition: ezuser.php:779
eZUser\removeUser
static removeUser( $userID)
Definition: ezuser.php:629
eZWishList\removeByUserID
static removeByUserID( $userID)
Definition: ezwishlist.php:225
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.