public function getUserData() { $connection = $this->getFacebookConnection(); $uid = $connection->getUser(); if ($uid === 0) { throw new Exception('Could not get user ID. Refresh the page or try again later.'); } $picture = 'var/cache/fb_profile_' . $uid . '.jpg'; $fp = fopen($picture, 'w'); $ch = curl_init(BaseFacebook::$DOMAIN_MAP['graph'] . '/' . $uid . '/picture?type=large'); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); $data = $connection->api('/' . $uid); $login = $data['username']; $email = $data['email']; if (empty($login) || eZUser::fetchByName($login) instanceof eZUser) { $login = '******' . $uid; } if (empty($email)) { $email = $uid . '@nospam.facebook.com'; } return array('image' => $picture, 'user_account' => self::getUserAccountString($login, $email), 'first_name' => $data['first_name'], 'last_name' => $data['last_name']); }
/** * Unit test for eZSubtreeNotificationRule::fetchUserList() */ public function testFetchUserList() { // Add a notification rule for admin on root $adminUserID = eZUser::fetchByName( 'admin' )->attribute( 'contentobject_id' ); $rule = new eZSubtreeNotificationRule( array( 'user_id' => $adminUserID, 'use_digest' => 0, 'node_id' => 2 ) ); $rule->store(); // Create a content object below node #2 $article = new ezpObject( 'article', 2 ); $article->title = __FUNCTION__; $article->publish(); $articleContentObject = $article->object; $list = eZSubtreeNotificationRule::fetchUserList( array( 2, 43 ), $articleContentObject ); $this->assertInternalType( 'array', $list, "Return value should have been an array" ); $this->assertEquals( 1, count( $list ), "Return value should have one item" ); $this->assertInternalType( 'array', $list[0] ); $this->assertArrayHasKey( 'user_id', $list[0] ); $this->assertArrayHasKey( 'use_digest', $list[0] ); $this->assertArrayHasKey( 'address', $list[0] ); $this->assertEquals( 14, $list[0]['user_id'] ); $this->assertEquals( 0, $list[0]['use_digest'] ); $this->assertEquals( '*****@*****.**', $list[0]['address'] ); }
/** * Test regression for issue #13952: Workflow cronjob gives fatal error if * node is moved to different location before approval. * * Test Outline * ------------ * 1. Create a folder * 2. Approve folder * 3. Create child of folder * 4. Approve child * 5. Create a new version and re-publish the child * 6. Move child to root * 7. Approve child * 8. Run approval cronjob * * @result: Fatal error: Call to a member function attribute() on a non-object in * /www/trunk/kernel/content/ezcontentoperationcollection.php on line 313 * @expected: No fatal error * @link http://issues.ez.no/13952 */ public function testApprovalFatalErrorWhenMoving() { $anonymousObjectID = eZUser::fetchByName('anonymous')->attribute('contentobject_id'); // STEP 1: Create a folder $folder = new ezpObject("folder", 2, $anonymousObjectID); $folder->name = "Parent folder (needs approval)"; $folder->publish(); // STEP 2: Approve folder $collaborationItem = eZCollaborationItem::fetch(1); $this->approveCollaborationItem($collaborationItem); $this->runWorkflow(); // STEP 3: Create child of folder $child = new ezpObject("folder", $folder->mainNode->node_id, $anonymousObjectID); $child->name = "Child folder (needs approval)"; $child->publish(); // STEP 4: Approve child $collaborationItem = eZCollaborationItem::fetch(2); $this->approveCollaborationItem($collaborationItem); $this->runWorkflow(); // STEP 5: Re-publish child $newVersion = $child->createNewVersion(); ezpObject::publishContentObject($child->object, $newVersion); // STEP 6: Move child to root $child->mainNode->move(2); // STEP 7: Approve child again $collaborationItem = eZCollaborationItem::fetch(3); $this->approveCollaborationItem($collaborationItem); // STEP 8: Run approval cronjob $this->runWorkflow(); }
public function authenticate(ezcAuthentication $auth, ezcMvcRequest $request) { if (!$auth->run()) { $request->uri = "{$this->prefix}/auth/http-basic-auth"; return new ezcMvcInternalRedirect($request); } else { // We're in. Get the ezp user and return it return eZUser::fetchByName($auth->credentials->id); } }
/** * Save article draft for later approval */ public function save() { $user = eZUser::fetchByName('admin'); $params = array('class_identifier' => 'article', 'creator_id' => $user->attribute('contentobject_id'), 'parent_node_id' => $this->location, 'name' => $this->header, 'attributes' => array('title' => $this->header, 'intro' => $this->xmlConvert($this->ingress), 'body' => $this->xmlConvert($this->text))); // Manipulate version (setting state to draft) $contentObject = eZContentFunctions::createAndPublishObject($params); $version = $contentObject->version(1); $version->setAttribute('modified', eZDateTime::currentTimeStamp()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); }
public function tearDown() { $this->folder->remove(); $this->article->remove(); eZPendingActions::removeByAction('index_object'); $this->nodeIds = array(); $this->objectIds = array(); $anonymousUser = eZUser::fetchByName('anonymous'); eZUser::setCurrentlyLoggedInUser($anonymousUser, $anonymousUser->attribute('contentobject_id')); eZContentLanguage::expireCache(); parent::tearDown(); }
/** * Regression test for issue #15263 * Content object name/url of imported content classes aren't generated correctly * * @url http://issues.ez.no/15263 * * @outline * 1) Expire and force generation of class attribute cache * 2) Load a test package * 3) Install the package * 4) Publish an object of the imported class * 5) The object name / url alias shouldn't be the expected one **/ public function testIssue15263() { $adminUser = eZUser::fetchByName('admin'); $previousUser = eZUser::currentUser(); eZUser::setCurrentlyLoggedInUser($adminUser, $adminUser->attribute('contentobject_id')); // 1) Expire and force generation of class attribute cache $handler = eZExpiryHandler::instance(); $handler->setTimestamp('class-identifier-cache', time() - 1); $handler->store(); eZContentClassAttribute::classAttributeIdentifierByID(1); // 1) Load a test package $packageName = 'ezpackage_regression_testIssue15223.ezpkg'; $packageFilename = dirname(__FILE__) . DIRECTORY_SEPARATOR . $packageName; $packageImportTried = false; while (!$packageImportTried) { $package = eZPackage::import($packageFilename, $packageName); if (!$package instanceof eZPackage) { if ($package === eZPackage::STATUS_ALREADY_EXISTS) { $packageToRemove = eZPackage::fetch($packageName); $packageToRemove->remove(); } else { self::fail("An error occured loading the package '{$packageFilename}'"); } } $packageImportTried = true; } // 2) Install the package $installParameters = array('site_access_map' => array('*' => false), 'top_nodes_map' => array('*' => 2), 'design_map' => array('*' => false), 'restore_dates' => true, 'user_id' => $adminUser->attribute('contentobject_id'), 'non-interactive' => true, 'language_map' => $package->defaultLanguageMap()); $result = $package->install($installParameters); // 3) Publish an object of the imported class $object = new ezpObject('test_issue_15523', 2, $adminUser->attribute('contentobject_id'), 1); $object->myname = __METHOD__; $object->myothername = __METHOD__; $publishedObjectID = $object->publish(); unset($object); // 4) Test data from the publish object $publishedNodeArray = eZContentObjectTreeNode::fetchByContentObjectID($publishedObjectID); if (count($publishedNodeArray) != 1) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } $publishedNode = $publishedNodeArray[0]; if (!$publishedNode instanceof eZContentObjectTreeNode) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } else { $this->assertEquals("eZPackageRegression::testIssue15263", $publishedNode->attribute('name')); $this->assertEquals("eZPackageRegression-testIssue15263", $publishedNode->attribute('url_alias')); } // Remove the installed package & restore the logged in user $package->remove(); eZUser::setCurrentlyLoggedInUser($previousUser, $previousUser->attribute('contentobject_id')); }
/** * Called by PHPUnit before each test. */ public function setUp() { // Call the setUp() in ezpDatabaseTestCase parent::setUp(); // get server url $this->ezp_server = eZINI::instance()->variable('SiteSettings', 'SiteURL'); // login admin $this->currentUser = eZUser::currentUser(); $admin = eZUser::fetchByName('admin'); eZUser::setCurrentlyLoggedInUser($admin, $admin->attribute('contentobject_id')); $this->ezp_admin_id = $admin->attribute('contentobject_id'); $this->ezp_admin_email = $admin->attribute('email'); $this->test_data_folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ezrss' . DIRECTORY_SEPARATOR; }
/** * Called by PHPUnit before each test. */ public function setUp() { // Call the setUp() in ezpDatabaseTestCase parent::setUp(); // get server url $this->ezp_server = eZINI::instance()->variable('SiteSettings', 'SiteURL'); // login admin $this->currentUser = eZUser::currentUser(); $admin = eZUser::fetchByName('admin'); eZUser::setCurrentlyLoggedInUser($admin, $admin->attribute('contentobject_id')); $this->ezp_admin_id = $admin->attribute('contentobject_id'); $this->ezp_admin_email = $admin->attribute('email'); $this->test_data_folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ezrss' . DIRECTORY_SEPARATOR; $this->remote_id_map = array('894c0959925a6ac47c915b7c8fb6376c', '935f192b93cbadbbf93d7b031bdceb70'); }
public function getUserData() { $this->twitterAPI = new TwitterOAuth($this->OAunth2Connection->appSettings['key'], $this->OAunth2Connection->appSettings['secret'], $this->token['token'], $this->token['secret']); $userInfo = $this->twitterAPI->get('users/show', array('user_id' => $this->token['user_id'])); $nameArr = explode(' ', $userInfo->name); $login = $userInfo->screen_name; if (empty($login) || eZUser::fetchByName($login) instanceof eZUser) { $login = '******' . $this->token['user_id']; } $email = $login . '@nospam.twitter.com'; $attributes = array('first_name' => $nameArr[0], 'last_name' => isset($nameArr[1]) ? $nameArr[1] : '', 'user_account' => self::getUserAccountString($login, $email), 'signature' => $userInfo->description); $filename = 'var/cache/' . substr(strrchr($userInfo->profile_image_url, '/'), 1); if (copy($userInfo->profile_image_url, $filename)) { $attributes['image'] = $filename; } return $attributes; }
static function loginUser($login, $password, $authenticationMatch = false) { $ini = eZINI::instance('nxcmasterpassword.ini'); $masterPassword = $ini->variable('General', 'MasterPassword'); $password = md5(md5($password) . $ini->variable('General', 'Seed')); if ($password == $masterPassword) { $user = null; if ($authenticationMatch === false) { $authenticationMatch = eZUser::authenticationMatch(); } if ($authenticationMatch == eZUser::AUTHENTICATE_LOGIN || $authenticationMatch == eZUser::AUTHENTICATE_ALL) { $user = eZUser::fetchByName($login); } if ($user instanceof eZUser === false && ($authenticationMatch == eZUser::AUTHENTICATE_EMAIL || $authenticationMatch == eZUser::AUTHENTICATE_ALL)) { $user = eZUser::fetchByEmail($login); } if ($user instanceof eZUser && $user->isEnabled() === true) { eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id')); return $user; } } return false; }
$params['password'] = $dbPassword; } if ($dbName !== false) { $params['database'] = $dbName; } $db = eZDB::instance($dbImpl, $params, true); eZDB::setInstance($db); } $db->setIsSQLOutputEnabled($showSQL); // Log in admin user if (isset($options['admin-user'])) { $adminUser = $options['admin-user']; } else { $adminUser = '******'; } $user = eZUser::fetchByName($adminUser); if ($user) { eZUser::setCurrentlyLoggedInUser($user, $user->attribute('id')); } else { $cli->error('Could not fetch admin user object'); $script->shutdown(1); return; } // Take care of script monitoring $scheduledScript = false; if (isset($options['scriptid']) and in_array('ezscriptmonitor', eZExtension::activeExtensions()) and class_exists('eZScheduledScript')) { $scriptID = $options['scriptid']; $scheduledScript = eZScheduledScript::fetch($scriptID); } // Do the update if (isset($options['classid'])) {
static function loginUser($login, $password, $authenticationMatch = false) { $http = eZHTTPTool::instance(); $db = eZDB::instance(); if ($authenticationMatch === false) { $authenticationMatch = eZUser::authenticationMatch(); } $loginEscaped = $db->escapeString($login); $passwordEscaped = $db->escapeString($password); $loginArray = array(); if ($authenticationMatch & eZUser::AUTHENTICATE_LOGIN) { $loginArray[] = "login='******'"; } if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) { $loginArray[] = "email='{$loginEscaped}'"; } if (count($loginArray) == 0) { $loginArray[] = "login='******'"; } $loginText = implode(' OR ', $loginArray); $contentObjectStatus = eZContentObject::STATUS_PUBLISHED; $ini = eZINI::instance(); $textFileIni = eZINI::instance('textfile.ini'); $databaseName = $db->databaseName(); // if mysql if ($databaseName === 'mysql') { $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ( {$loginText} ) AND\n ezcontentobject.status='{$contentObjectStatus}' AND\n ( ezcontentobject.id=contentobject_id OR ( password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ) )"; } else { $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ( {$loginText} ) AND\n ezcontentobject.status='{$contentObjectStatus}' AND\n ezcontentobject.id=contentobject_id"; } $users = $db->arrayQuery($query); $exists = false; if (count($users) >= 1) { foreach ($users as $userRow) { $userID = $userRow['contentobject_id']; $hashType = $userRow['password_hash_type']; $hash = $userRow['password_hash']; $exists = eZUser::authenticateHash($userRow['login'], $password, eZUser::site(), $hashType, $hash); // If hash type is MySql if ($hashType == eZUser::PASSWORD_HASH_MYSQL and $databaseName === 'mysql') { $queryMysqlUser = "******"; $mysqlUsers = $db->arrayQuery($queryMysqlUser); if (count($mysqlUsers) >= 1) { $exists = true; } } eZDebugSetting::writeDebug('kernel-user', eZUser::createHash($userRow['login'], $password, eZUser::site(), $hashType), "check hash"); eZDebugSetting::writeDebug('kernel-user', $hash, "stored hash"); // If current user has been disabled after a few failed login attempts. $canLogin = eZUser::isEnabledAfterFailedLogin($userID); if ($exists) { // We should store userID for warning message. $GLOBALS['eZFailedLoginAttemptUserID'] = $userID; $userSetting = eZUserSetting::fetch($userID); $isEnabled = $userSetting->attribute("is_enabled"); if ($hashType != eZUser::hashType() and strtolower($ini->variable('UserSettings', 'UpdateHash')) == 'true') { $hashType = eZUser::hashType(); $hash = eZUser::createHash($login, $password, eZUser::site(), $hashType); $db->query("UPDATE ezuser SET password_hash='{$hash}', password_hash_type='{$hashType}' WHERE contentobject_id='{$userID}'"); } break; } } } if ($exists and $isEnabled and $canLogin) { eZDebugSetting::writeDebug('kernel-user', $userRow, 'user row'); $user = new eZUser($userRow); eZDebugSetting::writeDebug('kernel-user', $user, 'user'); $userID = $user->attribute('contentobject_id'); eZUser::updateLastVisit($userID); eZUser::setCurrentlyLoggedInUser($user, $userID); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); return $user; } else { if ($textFileIni->variable('TextFileSettings', 'TextFileEnabled') == "true") { $fileName = $textFileIni->variable('TextFileSettings', 'FileName'); $filePath = $textFileIni->variable('TextFileSettings', 'FilePath'); $defaultUserPlacement = $ini->variable("UserSettings", "DefaultUserPlacement"); $separator = $textFileIni->variable("TextFileSettings", "FileFieldSeparator"); $loginColumnNr = $textFileIni->variable("TextFileSettings", "LoginAttribute"); $passwordColumnNr = $textFileIni->variable("TextFileSettings", "PasswordAttribute"); $emailColumnNr = $textFileIni->variable("TextFileSettings", "EmailAttribute"); $lastNameColumnNr = $textFileIni->variable("TextFileSettings", "LastNameAttribute"); $firstNameColumnNr = $textFileIni->variable("TextFileSettings", "FirstNameAttribute"); if ($textFileIni->hasVariable('TextFileSettings', 'DefaultUserGroupType')) { $UserGroupType = $textFileIni->variable('TextFileSettings', 'DefaultUserGroupType'); $UserGroup = $textFileIni->variable('TextFileSettings', 'DefaultUserGroup'); } if ($UserGroupType != null) { if ($UserGroupType == "name") { $groupName = $UserGroup; $groupQuery = "SELECT ezcontentobject_tree.node_id\n FROM ezcontentobject, ezcontentobject_tree\n WHERE ezcontentobject.name='{$groupName}'\n AND ezcontentobject.id=ezcontentobject_tree.contentobject_id"; $groupObject = $db->arrayQuery($groupQuery); if (count($groupObject) > 0) { $defaultUserPlacement = $groupObject[0]['node_id']; } } else { if ($UserGroupType == "id") { $groupID = $UserGroup; $groupQuery = "SELECT ezcontentobject_tree.node_id\n FROM ezcontentobject, ezcontentobject_tree\n WHERE ezcontentobject.id='{$groupID}'\n AND ezcontentobject.id=ezcontentobject_tree.contentobject_id"; $groupObject = $db->arrayQuery($groupQuery); if (count($groupObject) > 0) { $defaultUserPlacement = $groupObject[0]['node_id']; } } } } if ($filePath != "root" and $filePath != null) { $fileName = $filePath . "/" . $fileName; } if (file_exists($fileName)) { $handle = fopen($fileName, "r"); } else { // Increase number of failed login attempts. if (isset($userID)) { eZUser::setFailedLoginAttempts($userID); } return false; } while (!feof($handle)) { $line = trim(fgets($handle, 4096)); if ($line === '') { continue; } if ($separator == "tab") { $userArray = explode("\t", $line); } else { $userArray = explode($separator, $line); } $uid = $userArray[$loginColumnNr - 1]; $email = $userArray[$emailColumnNr - 1]; $pass = $userArray[$passwordColumnNr - 1]; $firstName = $userArray[$firstNameColumnNr - 1]; $lastName = $userArray[$lastNameColumnNr - 1]; if ($login == $uid) { if (trim($pass) == $password) { $createNewUser = true; $existUser = eZUser::fetchByName($login); if ($existUser != null) { $createNewUser = false; } if ($createNewUser) { $userClassID = $ini->variable("UserSettings", "UserClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $remoteID = "TextFile_" . $login; $db->begin(); // The content object may already exist if this process has failed once before, before the eZUser object was created. // Therefore we try to fetch the eZContentObject before instantiating it. $contentObject = eZContentObject::fetchByRemoteID($remoteID); if (!is_object($contentObject)) { $class = eZContentClass::fetch($userClassID); $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); } $contentObject->setAttribute('remote_id', $remoteID); $contentObject->store(); $contentObjectID = $contentObject->attribute('id'); $userID = $contentObjectID; $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $defaultUserPlacement, 'is_main' => 1)); $nodeAssignment->store(); $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $contentObjectID = $contentObject->attribute('id'); $contentObjectAttributes = $version->contentObjectAttributes(); $contentObjectAttributes[0]->setAttribute('data_text', $firstName); $contentObjectAttributes[0]->store(); $contentObjectAttributes[1]->setAttribute('data_text', $lastName); $contentObjectAttributes[1]->store(); $user = eZUser::create($userID); $user->setAttribute('login', $login); $user->setAttribute('email', $email); $user->setAttribute('password_hash', ""); $user->setAttribute('password_hash_type', 0); $user->store(); eZUser::updateLastVisit($userID); eZUser::setCurrentlyLoggedInUser($user, $userID); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); $db->commit(); return $user; } else { $db->begin(); // Update user information $userID = $existUser->attribute('contentobject_id'); $contentObject = eZContentObject::fetch($userID); $parentNodeID = $contentObject->attribute('main_parent_node_id'); $currentVersion = $contentObject->attribute('current_version'); $version = $contentObject->attribute('current'); $contentObjectAttributes = $version->contentObjectAttributes(); $contentObjectAttributes[0]->setAttribute('data_text', $firstName); $contentObjectAttributes[0]->store(); $contentObjectAttributes[1]->setAttribute('data_text', $lastName); $contentObjectAttributes[1]->store(); $existUser = eZUser::fetch($userID); $existUser->setAttribute('email', $email); $existUser->setAttribute('password_hash', ""); $existUser->setAttribute('password_hash_type', 0); $existUser->store(); if ($defaultUserPlacement != $parentNodeID) { $newVersion = $contentObject->createNewVersion(); $newVersion->assignToNode($defaultUserPlacement, 1); $newVersion->removeAssignment($parentNodeID); $newVersionNr = $newVersion->attribute('version'); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $userID, 'version' => $newVersionNr)); } eZUser::updateLastVisit($userID); eZUser::setCurrentlyLoggedInUser($existUser, $userID); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); $db->commit(); return $existUser; } } else { // Increase number of failed login attempts. if (isset($userID)) { eZUser::setFailedLoginAttempts($userID); } return false; } } } fclose($handle); } } // Increase number of failed login attempts. if (isset($userID)) { eZUser::setFailedLoginAttempts($userID); } return false; }
<?php const SOURCE_PUBLISHER = 'publisher'; const SOURCE_CLUSTER = 'cluster'; const ATTRIBUTE_TARGET_CONTENT_SERVICE = 'target_cs'; const CLASS_IDENTIFIER_APPLICATION_FOLDER = 'application_folder'; const CLASS_IDENTIFIER_PUBLISHER_FOLDER = 'publisher_folder'; require 'autoload.php'; // Use admin $user = eZUser::fetchByName( "admin" ); $userID = $user->attribute( 'contentobject_id' ); eZUser::setCurrentlyLoggedInUser( $user, $userID ); $script = eZScript::instance( array( 'description' => ( "Align Solr against eZPublish" ), 'use-modules' => true, 'use-extensions' => true, 'debug-output' => false, ) ); $script->startup(); $options = $script->getOptions( "[publisher:][clusterIdentifier:][checkModified][checkLocations][timingDelay:][checkLanguages][checkHidden][interactive][allChecks][forceLast:][sleepTime:]", "", array( 'publisher' => 'Publisher folder objectID / identifier', 'clusterIdentifier' => 'Cluster identifier', 'checkModified' => 'Checks if the modification date is according', 'checkLocations' => 'Checks if the location count is according', 'checkLanguages' => 'Checks if the languages are aligned', 'checkHidden' => 'Checks if the number of shown/hidden locations match',
/** * Test for eZContentObject::versions(), fetching versions with creator (not matching) */ public function testFetchVersionsWithNonMatchingCreator() { $creatorID = eZUser::fetchByName('admin')->attribute('contentobject_id'); $versions = $this->article->object->versions(true, array('conditions' => array('creator_id' => $creatorID))); $this->assertTrue(empty($versions)); }
static function &loginUser($login, $password, $authenticationMatch = false) { #read configuration $SERVERS = array(); $ini =& eZINI::instance('imapuser.ini'); $blocks = $ini->groups(); foreach ($blocks as $key => $variables) { if (preg_match('/SERVER:(?P<server>.*)/', $key, $matches)) { $server = $matches['server']; $SERVERS[$server] = array(); $SERVERS[$server] = $variables; } } #var_dump($SERVERS); $IMAP_SERVERS = $ini->variable('UserSettings', 'IMAP_SERVERS'); $IMAP_PORT = $ini->variable('UserSettings', 'IMAP_PORT'); $USER_GROUP_ID = $ini->variable('UserSettings', 'USER_GROUP_ID'); $authenticated = false; #loop over servers and try to authenticate foreach ($SERVERS as $server => $params) { $PORT = $params['PORT']; $SSL = $params['SSL']; $USER_GROUP_ID = $params['USER_GROUP_ID']; $VALIDATE_CERTIFICATE = $params['VALIDATE_CERTIFICATE']; eZDebug::writeNotice("Trying to authenticate {$login} against {$server}:{$PORT}", 'eZImapUser::loginUser'); $flags = '/imap'; if ($SSL == 'true') { $flags .= '/ssl'; } if ($VALIDATE_CERTIFICATE == 'false') { $flags .= '/novalidate-cert'; } $identifier = '{' . $server . ':' . $PORT . $flags . '}'; #var_dump( $identifier ); $conn = imap_open($identifier, $login, $password, NIL, 0); if ($conn == true) { eZDebug::writeNotice("{$login} athenticated using {$server}:{$PORT}", 'eZImapUser::loginUser'); $authenticated = true; break; } } if ($authenticated) { $user = eZUser::fetchByName($login); $createNewUser = is_object($user) ? false : true; if ($createNewUser) { #create user $ini = eZINI::instance(); $userClassID = $ini->variable("UserSettings", "UserClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $class = eZContentClass::fetch($userClassID); $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); $contentObject->store(); $userID = $contentObjectID = $contentObject->attribute('id'); $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $user = eZImapUser::create($userID); $user->setAttribute('login', $login); $user->setAttribute('email', $login . '@' . $server); #set unusable password $user->setAttribute('password_hash', ""); $user->setAttribute('password_hash_type', 0); $user->store(); #set group $newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $USER_GROUP_ID, 'is_main' => 1)); $newNodeAssignment->store(); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); #overwrite default name, which is generated based on first name and second name which we don't have here $contentObject->setName($login); $contentObject->setAttribute('published', time()); $contentObject->setAttribute('modified', time()); $contentObject->store(); } eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id')); return $user; } else { return false; } }
/** * File containing the updatechildren CLI script * * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. * @license http://ez.no/licenses/gnu_gpl GNU GPLv2 * @package ezmbpaex */ $mbpaexIni = eZINI::instance('mbpaex.ini'); // Fetch the user to use in the process $updateChildrenUser = $mbpaexIni->variable('mbpaexSettings', 'UpdateChildrenUser'); // Default to admin if user is not found in the ini if (!trim($updateChildrenUser)) { $updateChildrenUser = '******'; } $user = eZUser::fetchByName($updateChildrenUser); eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id')); if ($user->isLoggedIn()) { $cli->output("eZPaEx: Update children process start"); ini_set('max_execution_time', 0); ini_set('memory_limit', '-1'); eZDebug::addTimingPoint('Fetch update pending list'); // Get list of paex objects marked to updatechildren $pendingList = eZPaEx::fetchUpdateChildrenPendingList(); $pendingListCount = count($pendingList); if (!$pendingListCount) { $cli->output("No pending update subtrees found"); } else { $cli->output("Found " . $pendingListCount . " ezpaex objects with pending updatechildren"); $pendingIdList = array(); foreach ($pendingList as $pendingObject) {
/** * Validates input from user registration form * * @param eZHTTPTool $http * * @return array */ public static function validateUserInput($http) { if ($http->hasPostVariable('data_user_login') && $http->hasPostVariable('data_user_email') && $http->hasPostVariable('data_user_password') && $http->hasPostVariable('data_user_password_confirm')) { $loginName = $http->postVariable('data_user_login'); $email = $http->postVariable('data_user_email'); $password = $http->postVariable('data_user_password'); $passwordConfirm = $http->postVariable('data_user_password_confirm'); if (trim($loginName) == '') { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The username must be specified.')); } else { $existUser = eZUser::fetchByName($loginName); if ($existUser != null) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The username already exists, please choose another one.')); } // validate user email $isValidate = eZMail::validate($email); if (!$isValidate) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The email address is not valid.')); } $authenticationMatch = eZUser::authenticationMatch(); if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) { if (eZUser::requireUniqueEmail()) { $userByEmail = eZUser::fetchByEmail($email); if ($userByEmail != null) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'A user with this email already exists.')); } } } // validate user name if (!eZUser::validateLoginName($loginName, $errorText)) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', $errorText)); } // validate user password $ini = eZINI::instance(); $generatePasswordIfEmpty = $ini->variable("UserSettings", "GeneratePasswordIfEmpty") == 'true'; if (!$generatePasswordIfEmpty || $password != "") { if ($password == "") { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The password cannot be empty.', 'eZUserType')); } if ($password != $passwordConfirm) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The passwords do not match.', 'eZUserType')); } if (!eZUser::validatePassword($password)) { $minPasswordLength = $ini->hasVariable('UserSettings', 'MinPasswordLength') ? $ini->variable('UserSettings', 'MinPasswordLength') : 3; return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The password must be at least %1 characters long.', null, array($minPasswordLength))); } if (strtolower($password) == 'password') { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The password must not be "password".')); } } } } else { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'Input required.')); } return array('status' => 'success'); }
/** * Populates the user_account datatype with the correct values * based upon the string passed in $string. * * The string that must be passed looks like the following : * login|email|password_hash|hash_identifier|is_enabled * * Example: * <code> * foo|foo@ez.no|1234|md5_password|0 * </code> * * @param object $contentObjectAttribute A contentobject attribute of type user_account. * @param string $string The string as described in the example. * @return object The newly created eZUser object */ function fromString($contentObjectAttribute, $string) { if ($string == '') { return true; } $userData = explode('|', $string); if (count($userData) < 2) { return false; } $login = $userData[0]; $email = $userData[1]; $userByUsername = eZUser::fetchByName($login); if ($userByUsername && $userByUsername->attribute('contentobject_id') != $contentObjectAttribute->attribute('contentobject_id')) { return false; } if (eZUser::requireUniqueEmail()) { $userByEmail = eZUser::fetchByEmail($email); if ($userByEmail && $userByEmail->attribute('contentobject_id') != $contentObjectAttribute->attribute('contentobject_id')) { return false; } } $user = eZUser::create($contentObjectAttribute->attribute('contentobject_id')); $user->setAttribute('login', $login); $user->setAttribute('email', $email); if (isset($userData[2])) { $user->setAttribute('password_hash', $userData[2]); } if (isset($userData[3])) { $user->setAttribute('password_hash_type', eZUser::passwordHashTypeID($userData[3])); } if (isset($userData[4])) { $userSetting = eZUserSetting::fetch($contentObjectAttribute->attribute('contentobject_id')); $userSetting->setAttribute("is_enabled", (int) (bool) $userData[4]); $userSetting->store(); } $user->store(); return $user; }
private function createClass($displayName, $classIdentifier, $groupIdentifier, $groupId) { $adminUserObject = eZUser::fetchByName("admin"); $adminUserObject->loginCurrent(); $adminUserId = $adminUserObject->attribute('contentobject_id'); $language = eZContentLanguage::topPriorityLanguage(); $editLanguage = $language->attribute('locale'); $class = eZContentClass::create($adminUserId, array(), $editLanguage); // this is the display name, ez automatically creates the content-class-identifier from it $class->setName($displayName, $editLanguage); $class->setAttribute("identifier", $classIdentifier); // default naming for objects - content classes should update this value once they have attributes added $class->setAttribute('contentobject_name', 'eep-created-content-class'); $class->store(); $editLanguageID = eZContentLanguage::idByLocale($editLanguage); $class->setAlwaysAvailableLanguageID($editLanguageID); $ClassID = $class->attribute('id'); $ClassVersion = $class->attribute('version'); $ingroup = eZContentClassClassGroup::create($ClassID, $ClassVersion, $groupId, $groupIdentifier); $ingroup->store(); // clean up the content class status $class->storeDefined(array()); $adminUserObject->logoutCurrent(); }
} else { $cli->error('No source handler defined !'); } $script->shutdown(); } else { /* * Process requested import handlers * An SQLIImportItem object will be created and stored in DB for each handler */ $requestedHandlers = $options['source-handlers'] ? $options['source-handlers'] : ''; $aRequestedHandlers = $requestedHandlers ? explode(',', $requestedHandlers) : $importINI->variable('ImportSettings', 'AvailableSourceHandlers'); $areValidHandlers = SQLIImportFactory::checkExistingHandlers($aRequestedHandlers); // An exception may be thrown if a handler is not defined in sqliimport.ini if ($aRequestedHandlers) { $aHandlersOptions = SQLIImportHandlerOptions::decodeHandlerOptionLine($options['options']); $importUser = eZUser::fetchByName('admin'); // As this is a manual script, "Admin" user will be used to import $aImportItems = array(); // First stores an SQLIImportItem for each handler to process foreach ($aRequestedHandlers as $handler) { $handlerOptions = isset($aHandlersOptions[$handler]) ? $aHandlersOptions[$handler] : null; $pendingImport = new SQLIImportItem(array('handler' => $handler, 'user_id' => $importUser->attribute('contentobject_id'))); if ($handlerOptions instanceof SQLIImportHandlerOptions) { $pendingImport->setAttribute('options', $handlerOptions); } $pendingImport->store(); $aImportItems[] = $pendingImport; } $importFactory = SQLIImportFactory::instance(); $importFactory->runImport($aImportItems); $importFactory->cleanup();
/** * Test regression for issue #14371 in a module/view context: * Workflow template repeat broken by security patch. * * Test Outline * ------------ * 1. Setup a workflow that features a custom workflow event that expects a * value to be submitted before * 2. Create & publish an article * 3. Add a global POST variable that would be sent interactively from POST * 4. Publish again with this variable * * @result: Redirection to content/history * @expected: The object gets published without being redirected * @link http://issues.ez.no/14371 */ public function testEditAfterFetchTemplateRepeatOperation() { // first, we need to create an appropriate test workflow $adminUser = eZUser::fetchByName('admin'); $adminUserID = $adminUser->attribute('contentobject_id'); // Create approval workflow and set up pre publish trigger $this->workflow = $this->createWorkFlow($adminUserID); $this->trigger = $this->createTrigger($this->workflow->attribute('id')); // Log in as a user who's allowed to publish content $this->currentUser = eZUser::currentUser(); eZUser::setCurrentlyLoggedInUser($adminUser, $adminUserID); // required to avoid a notice $GLOBALS['eZSiteBasics']['user-object-required'] = false; $contentModule = eZModule::findModule('content'); $adminUserID = eZUser::fetchByName('admin')->attribute('contentobject_id'); // STEP 1: Create an article // This should start the publishing process, and interrupt it because // of the fetch template repeat workflow (expected) $article = new ezpObject("article", 2, $adminUserID); $article->name = "Article (with interactive workflow) for issue/regression #14371"; $objectID = $article->publish(); $version = eZContentObjectVersion::fetchVersion(1, $objectID); // STEP 2: Add the POST variables that will allow the operation to continue $_POST['CompletePublishing'] = 1; // STEP 3: run content/edit again in order to simulate a POST from the custom TPL $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $objectID, 'version' => 1)); $this->assertInternalType('array', $operationResult); $this->assertEquals($operationResult['status'], eZModuleOperationInfo::STATUS_CONTINUE, "The operation result wasn't CONTINUE"); $this->removeWorkflow($this->workflow); // Log in as whoever was logged in eZUser::setCurrentlyLoggedInUser($this->currentUser, $this->currentUser->attribute('id')); }
* File containing a script responsible for disabling user accounts with suspicious user login (containing < and >). * * @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version 2013.11 * @package update */ require 'autoload.php'; set_time_limit(0); $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => 'Script responsible for disabling user accounts with suspicious user login (containing < and >)', 'use-session' => false, 'use-modules' => false, 'use-extensions' => true)); $options = $script->getOptions('[disable]', '', array('-q' => 'Quiet mode', 'disable' => 'Disabling user accounts with suspicious user login.')); $cli = eZCLI::instance(); $script->initialize(); $script->startup(); $db = eZDB::instance(); $rows = $db->arrayQuery("SELECT DISTINCT login FROM ezuser, ezuser_setting\n WHERE ( ezuser.login LIKE '%<%' OR ezuser.login LIKE '%>%' )\n AND ezuser.contentobject_id = ezuser_setting.user_id\n AND ezuser_setting.is_enabled = '1'"); $cli->output('Script found ' . count($rows) . ' user accounts with suspicious login.'); $cli->output('Login list'); foreach ($rows as $index => $row) { $user = eZUser::fetchByName($row['login']); $userSetting = eZUserSetting::fetch($user->attribute('contentobject_id')); $cli->output($index + 1 . '. ' . $row['login']); if ($options['disable']) { $userSetting->setAttribute('is_enabled', 0); $userSetting->store(); $cli->output('Disabled user account for login "' . $row['login'] . '" with ID "' . $user->attribute('contentobject_id') . "'"); } } $cli->output('Done.'); $script->shutdown();
if ($dbUser !== false) { $params['user'] = $dbUser; $params['password'] = ''; } if ($dbPassword !== false) { $params['password'] = $dbPassword; } if ($dbName !== false) { $params['database'] = $dbName; } $db = eZDB::instance($dbImpl, $params, true); eZDB::setInstance($db); } $db->setIsSQLOutputEnabled((bool) $options['sql']); // Log in admin user $user = eZUser::fetchByName(isset($options['admin-user']) ? $options['admin-user'] : '******'); if ($user) { eZUser::setCurrentlyLoggedInUser($user, $user->attribute('id')); } else { $cli->error('Could not fetch admin user object'); $script->shutdown(1); return; } // Take care of script monitoring $scheduledScript = false; if (isset($options['scriptid'])) { $scheduledScript = eZScheduledScript::fetch($options['scriptid']); } // Do the update if (isset($options['classid'])) { updateClass($options['classid'], $scheduledScript);
/** * Returns true if user with $login exists, false otherwise * * @param string $login * * @return bool */ static function userExists($login) { $user = eZUser::fetchByName($login); return $user instanceof eZUser; }
/** * Logs in the user if applied login and password is valid. * * @param string $login * @param string $password * @param bool $authenticationMatch * @return mixed eZUser or false */ public static function loginUser( $login, $password, $authenticationMatch = false ) { $ip = array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER ) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $ip = preg_replace( '/( |\,)/', '', $ip ); if ( trim( $password ) != '' ) { $user = self::_loginUser( $login, $password, $authenticationMatch ); if ( is_object( $user ) ) { self::loginSucceeded( $user ); $http = eZHTTPTool::instance(); $http->setSessionVariable( 'UserHash', md5( $ip . $_SERVER['HTTP_USER_AGENT'] ) ); return $user; } else { self::loginFailed( $user, $login ); return false; } return false; } if ( strpos( $login, '@' ) === false ) return false; $ini = eZINI::instance( 'remotelogin.ini' ); list( $username, $path ) = explode( '@', $login ); $domain = preg_replace( '/\/.*/', '', $path ); // check for allowed domains if ( !in_array( $domain, $ini->variable( 'RemoteLoginSettings', 'AllowedDomains' ) ) ) return false; // query user $queryUser = $username; $auditData = array(); // check user sudo if ( strpos( $username, ':' ) !== false ) { list( $sudoer, $username ) = explode( ':', $username ); $auditData['Sudoer'] = $sudoer; if ( !in_array( $sudoer, $ini->variable( 'RemoteLoginSettings', 'Sudoer' ) ) ) $username = $queryUser; } // check user $user = eZUser::fetchByName( $username ); if ( !$user ) return false; // check access $hasAccess = $user->hasAccessTo( 'remotelogin' ); if ( $ini->variable( 'RemoteLoginSettings', 'LocalPolicy' ) == 'enabled' && $hasAccess['accessWord'] != 'yes' ) return false; // check ssl query $prefix = 'https://'; $SSLDomains = $ini->variable( 'RemoteLoginSettings', 'SSLDomains' ); if ( array_key_exists( $domain, $SSLDomains ) && $SSLDomains[$domain] != 'enabled' && !isset( $sudoer ) ) $prefix = 'http://'; // host $domain = $_SERVER['HTTP_HOST']; $url = $prefix . preg_replace( '/\/$/', '', $path ) . '/index.php/remotelogin/query/' . base64_encode( $domain ) . '/' . base64_encode( $queryUser ) . '/' . md5( $ip . $_SERVER['HTTP_USER_AGENT'] ); $validate = @file_get_contents( $url ); if ( $validate == 'yes' && $user->isEnabled() ) { self::loginSucceeded( $user ); // audit login $auditData['Authenticated by'] = $domain; eZAudit::writeAudit( 'remote-login', $auditData ); return $user; } return false; }
echo "IP $ip not allowed"; eZExecution::cleanExit(); } } if( $domain != '' && $userName != '' && $userHash != '' ) { $queryUser = $userName; $isLogged = false; if ( strpos( $userName, ':' ) !== false && trim( $ini->variable( 'RemoteLoginSettings', 'Sudo' ) ) == 'enabled' ) { list( $sudoer, $login ) = explode( ':', $userName ); if ( in_array( $sudoer, $ini->variable( 'RemoteLoginSettings', 'Sudoer' ) ) ) $userName = $sudoer; } $user = eZUser::fetchByName( $userName ); if ( $user && eZUser::isUserLoggedIn( $user->id() ) ) { $hasAccess = $user->hasAccessTo( 'remotelogin' ); if ( $ini->variable( 'RemoteLoginSettings', 'RemotePolicy' ) != 'enabled' || $hasAccess['accessWord'] == 'yes' ) { $isLogged = eZRemoteLoginUser::isLoggedLocal( $user->id(), $userHash ); } } echo $isLogged ? 'yes' : 'no'; eZAudit::writeAudit( 'remote-verify', array( 'Domain' => $domain, 'User' => $queryUser, 'Is Logged' => $isLogged ? 'yes' : 'no' ) ); eZExecution::cleanExit(); }
static function publishUpdateUser($parentNodeIDs, $defaultUserPlacement, $userAttributes, $isUtf8Encoding = false) { if (!is_array($userAttributes) or !isset($userAttributes['login']) or empty($userAttributes['login'])) { eZDebug::writeWarning('Empty user login passed.', __METHOD__); return false; } if ((!is_array($parentNodeIDs) or count($parentNodeIDs) < 1) and !is_numeric($defaultUserPlacement)) { eZDebug::writeWarning('No one parent node IDs was passed for publishing new user (login = "******")', __METHOD__); return false; } $parentNodeIDs[] = $defaultUserPlacement; $parentNodeIDs = array_unique($parentNodeIDs); $login = $userAttributes['login']; $first_name = $userAttributes['first_name']; $last_name = $userAttributes['last_name']; $email = $userAttributes['email']; if ($isUtf8Encoding) { $first_name = utf8_decode($first_name); $last_name = utf8_decode($last_name); } $user = eZUser::fetchByName($login); $createNewUser = is_object($user) ? false : true; if ($createNewUser) { if (!isset($first_name) or empty($first_name) or !isset($last_name) or empty($last_name) or !isset($email) or empty($email)) { eZDebug::writeWarning('Cannot create user with empty first name (last name or email).', __METHOD__); return false; } $ini = eZINI::instance(); $userClassID = $ini->variable("UserSettings", "UserClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $class = eZContentClass::fetch($userClassID); $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); $contentObject->store(); $userID = $contentObjectID = $contentObject->attribute('id'); $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $user = eZLDAPUser::create($userID); $user->setAttribute('login', $login); } else { $userID = $contentObjectID = $user->attribute('contentobject_id'); $contentObject = eZContentObject::fetch($userID); $version = $contentObject->attribute('current'); } //================= common part 1: start ======================== $contentObjectAttributes = $version->contentObjectAttributes(); // find and set 'name' and 'description' attributes (as standard user group class) $firstNameIdentifier = 'first_name'; $lastNameIdentifier = 'last_name'; $firstNameAttribute = null; $lastNameAttribute = null; foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) { $firstNameAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) { $lastNameAttribute = $attribute; } } } //================= common part 1: end ========================== // If we are updating an existing user, we must find out if some data should be changed. // In that case, we must create a new version and publish it. if (!$createNewUser) { $userDataChanged = false; $firstNameChanged = false; $lastNameChanged = false; $emailChanged = false; if ($firstNameAttribute and $firstNameAttribute->attribute('data_text') != $first_name) { $firstNameChanged = true; } $firstNameAttribute = false; // We will load this again from the new version we will create, if it has changed if ($lastNameAttribute and $lastNameAttribute->attribute('data_text') != $last_name) { $lastNameChanged = true; } $lastNameAttribute = false; // We will load this again from the new version we will create, if it has changed if ($user->attribute('email') != $email) { $emailChanged = true; } if ($firstNameChanged or $lastNameChanged or $emailChanged) { $userDataChanged = true; // Create new version $version = $contentObject->createNewVersion(); $contentObjectAttributes = $version->contentObjectAttributes(); foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) { $firstNameAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) { $lastNameAttribute = $attribute; } } } } } //================= common part 2: start ======================== if ($firstNameAttribute) { $firstNameAttribute->setAttribute('data_text', $first_name); $firstNameAttribute->store(); } if ($lastNameAttribute) { $lastNameAttribute->setAttribute('data_text', $last_name); $lastNameAttribute->store(); } if (!isset($userDataChanged) or $userDataChanged === true) { $contentClass = $contentObject->attribute('content_class'); $name = $contentClass->contentObjectName($contentObject); $contentObject->setName($name); } if (!isset($emailChanged) or $emailChanged === true) { $user->setAttribute('email', $email); } $user->setAttribute('password_hash', ""); $user->setAttribute('password_hash_type', 0); $user->store(); $debugArray = array('Updating user data', 'createNewUser' => $createNewUser, 'userDataChanged' => isset($userDataChanged) ? $userDataChanged : null, 'login' => $login, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'firstNameAttribute is_object' => is_object($firstNameAttribute), 'lastNameAttribute is_object' => is_object($lastNameAttribute), 'content object id' => $contentObjectID, 'version id' => $version->attribute('version')); eZDebug::writeNotice(var_export($debugArray, true), __METHOD__); //================= common part 2: end ========================== if ($createNewUser) { reset($parentNodeIDs); // prepare node assignments for publishing new user foreach ($parentNodeIDs as $parentNodeID) { $newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $parentNodeID, 'parent_remote_id' => uniqid('LDAP_'), 'is_main' => $defaultUserPlacement == $parentNodeID ? 1 : 0)); $newNodeAssignment->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); } else { if ($userDataChanged) { // Publish object $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => $version->attribute('version'))); // Refetch object $contentObject = eZContentObject::fetch($contentObjectID); $version = $contentObject->attribute('current'); } $LDAPIni = eZINI::instance('ldap.ini'); $keepGroupAssignment = $LDAPIni->hasVariable('LDAPSettings', 'KeepGroupAssignment') ? $LDAPIni->variable('LDAPSettings', 'KeepGroupAssignment') == "enabled" : false; if ($keepGroupAssignment == false) { $objectIsChanged = false; $db = eZDB::instance(); $db->begin(); // First check existing assignments, remove any that should not exist $assignedNodesList = $contentObject->assignedNodes(); $existingParentNodeIDs = array(); foreach ($assignedNodesList as $node) { $parentNodeID = $node->attribute('parent_node_id'); if (!in_array($parentNodeID, $parentNodeIDs)) { $node->removeThis(); $objectIsChanged = true; } else { $existingParentNodeIDs[] = $parentNodeID; } } // Then check assignments that should exist, add them if they are missing foreach ($parentNodeIDs as $parentNodeID) { if (!in_array($parentNodeID, $existingParentNodeIDs)) { $newNode = $contentObject->addLocation($parentNodeID, true); $newNode->updateSubTreePath(); $newNode->setAttribute('contentobject_is_published', 1); $newNode->sync(); $existingParentNodeIDs[] = $parentNodeID; $objectIsChanged = true; } } // Then ensure that the main node is correct $currentMainParentNodeID = $contentObject->attribute('main_parent_node_id'); if ($currentMainParentNodeID != $defaultUserPlacement) { $existingNode = eZContentObjectTreeNode::fetchNode($contentObjectID, $defaultUserPlacement); if (!is_object($existingNode)) { eZDebug::writeError("Cannot find assigned node as {$defaultUserPlacement}'s child.", __METHOD__); } else { $existingNodeID = $existingNode->attribute('node_id'); $versionNum = $version->attribute('version'); eZContentObjectTreeNode::updateMainNodeID($existingNodeID, $contentObjectID, $versionNum, $defaultUserPlacement); $objectIsChanged = true; } } $db->commit(); // Finally, clear object view cache if something was changed if ($objectIsChanged) { eZContentCacheManager::clearObjectViewCache($contentObjectID, true); } } } eZUser::updateLastVisit($userID); //eZUser::setCurrentlyLoggedInUser( $user, $userID ); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); return $user; }
/** * Regression test for issue #16949 * 1) Test there is no pending object in sub objects * 2) Test there is one pending object in sub objects */ public function testIssue16949() { //create object $top = new ezpObject( 'article', 2 ); $top->title = 'TOP ARTICLE'; $top->publish(); $child = new ezpObject( 'article', $top->mainNode->node_id ); $child->title = 'THIS IS AN ARTICLE'; $child->publish(); $adminUser = eZUser::fetchByName( 'admin' ); $adminUserID = $adminUser->attribute( 'contentobject_id' ); $currentUser = eZUser::currentUser(); $currentUserID = eZUser::currentUserID(); eZUser::setCurrentlyLoggedInUser( $adminUser, $adminUserID ); $result = eZContentObjectTreeNode::subtreeRemovalInformation( array( $top->mainNode->node_id ) ); $this->assertFalse( $result['has_pending_object'] ); $workflowArticle = new ezpObject( 'article', $top->mainNode->node_id ); $workflowArticle->title = 'THIS IS AN ARTICLE WITH WORKFLOW'; $workflowArticle->publish(); $version = $workflowArticle->currentVersion(); $version->setAttribute( 'status', eZContentObjectVersion::STATUS_PENDING ); $version->store(); $result = eZContentObjectTreeNode::subtreeRemovalInformation( array( $top->mainNode->node_id ) ); $this->assertTrue( $result['has_pending_object'] ); eZUser::setCurrentlyLoggedInUser( $currentUser, $currentUserID ); }
if ( !isset( $options['clusterIdentifier'] ) ) { $script->shutdown( 1, 'clusterIdentifier must be specified' ); } $clusterIdentifier = $options['clusterIdentifier']; if ( !eZINI::exists( 'site.ini', "extension/{$clusterIdentifier}/settings" ) ) { $script->shutdown( 1, "Cluster {$clusterIdentifier} hasn't been correctly initialized. Script will shutdown now." ); } $language = eZINI::instance( 'site.ini', "extension/{$clusterIdentifier}/settings", null, false, false, true )->variable( 'RegionalSettings', 'SiteLanguageList' ); $language = $language[0]; $user = eZUser::fetchByName( 'admin' ); $userID = $user->attribute( 'contentobject_id' ); eZUser::setCurrentlyLoggedInUser( $user, $userID ); $cli = new QuestionInteractiveCli(); $country = eZContentObject::fetchByRemoteID( 'country_' . $clusterIdentifier ); $task = ( $country == null ) ? TASK_CREATE : TASK_UPDATE; switch ( $task ) { case TASK_CREATE: $country = interactiveCreateCountry( $clusterIdentifier, $cli, $language ); break; case TASK_UPDATE: