/** * Returns the eZUserAccountKey associated with this user * * @return eZUserAccountKey */ public function accountKey() { return eZUserAccountKey::fetchByUserID($this->ContentObjectID); }
/** * Activate user with user or deactivate and create new eZUserAccountKey with user hash * depending on $enableUser being true or not. * * @param int $userID * @param string $userHash * @param bool $enableUser * * @return array An array with operation status, always true if userID is ok */ public static function activation($userID, $userHash, $enableUser = false) { $user = eZUser::fetch($userID); $userSetting = eZUserSetting::fetch($userID); if ($user && $userSetting) { $userChange = $userSetting->attribute('is_enabled') != $enableUser; if ($enableUser) { $userSetting->setAttribute('is_enabled', 1); $userSetting->store(); eZUserAccountKey::removeByUserID($userID); } else { $userSetting->setAttribute('is_enabled', 0); $userSetting->store(); $accountKey = eZUserAccountKey::createNew($userID, $userHash, time()); $accountKey->store(); } if ($userChange) { if (!$enableUser) { eZUser::removeSessionData($userID); } eZContentCacheManager::clearContentCacheIfNeeded($userID); } return array('status' => true); } else { eZDebug::writeError("Failed to activate user {$userID} (could not fetch)", __METHOD__); return array('status' => false); } }
static function removeByUserID($userID) { eZPersistentObject::removeObject(eZUserAccountKey::definition(), array('user_id' => $userID)); }
$hash = trim($http->hasPostVariable('Hash') ? $http->postVariable('Hash') : $Params['Hash']); $mainNodeID = (int) $http->hasPostVariable('MainNodeID') ? $http->postVariable('MainNodeID') : $Params['MainNodeID']; // Prepend or append the hash string with a salt, and md5 the resulting hash // Example: use is login name as salt, and a 'secret password' as hash sent to the user if ($http->hasPostVariable('HashSaltPrepend')) { $hash = md5(trim($http->postVariable('HashSaltPrepend')) . $hash); } else { if ($http->hasPostVariable('HashSaltAppend')) { $hash = md5($hash . trim($http->postVariable('HashSaltAppend'))); } } // Check if key exists $accountActivated = false; $alreadyActive = false; $isPending = false; $accountKey = $hash ? eZUserAccountKey::fetchByKey($hash) : false; if ($accountKey) { $accountActivated = true; $userID = $accountKey->attribute('user_id'); $userContentObject = eZContentObject::fetch($userID); if (!$userContentObject instanceof eZContentObject) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } if ($userContentObject->attribute('main_node_id') != $mainNodeID) { return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } // Enable user account if (eZOperationHandler::operationIsAvailable('user_activation')) { $operationResult = eZOperationHandler::execute('user', 'activation', array('user_id' => $userID, 'user_hash' => $hash, 'is_enabled' => true)); } else { eZUserOperationCollection::activation($userID, $hash, true);
$tpl->setVariable('errors_remove', empty($errors) ? false : $errors); } } $limitPreference = 'admin_user_actions_list_limit'; switch (eZPreferences::value($limitPreference)) { case 2: $limit = 25; break; case 3: $limit = 50; break; case 1: default: $limit = 10; } $unactivatedCount = eZUserAccountKey::count(eZUserAccountKey::definition()); $unactivated = array(); $availableSortFields = array('time' => 'time', 'login' => 'login', 'email' => 'email'); $availableSortOrders = array('asc' => 'asc', 'desc' => 'desc'); // default sort field/sort order $SortField = 'time'; $SortOrder = 'asc'; if (isset($Params['SortField']) && $availableSortFields[$Params['SortField']]) { $SortField = $Params['SortField']; } if (isset($Params['SortOrder']) && $availableSortOrders[$Params['SortOrder']]) { $SortOrder = $Params['SortOrder']; } if ($unactivatedCount > 0) { $unactivated = eZUser::fetchUnactivated(array($SortField => $SortOrder), $limit, $Offset); }
static function removeUser( $userID ) { $user = eZUser::fetch( $userID ); if ( !$user ) { eZDebug::writeError( "unable to find user with ID $userID", __METHOD__ ); return false; } eZUser::removeSessionData( $userID ); eZSubtreeNotificationRule::removeByUserID( $userID ); eZCollaborationNotificationRule::removeByUserID( $userID ); eZUserSetting::removeByUserID( $userID ); eZUserAccountKey::removeByUserID( $userID ); eZForgotPassword::removeByUserID( $userID ); eZWishList::removeByUserID( $userID ); // only remove general digest setting if there are no other users with the same e-mail $email = $user->attribute( 'email' ); $usersWithEmailCount = eZPersistentObject::count( eZUser::definition(), array( 'email' => $email ) ); if ( $usersWithEmailCount == 1 ) { eZGeneralDigestUserSettings::removeByAddress( $email ); } eZPersistentObject::removeObject( eZUser::definition(), array( 'contentobject_id' => $userID ) ); return true; }