Create User

Author Message

Brijesh Tekrawala

Thursday 17 February 2011 11:50:11 pm

I am creating user from PHP code but it is not working

function createUser($parentNodeId, $userClassId, $sectionId, $login, $email, $password, $dataTextAttributeList){ $class = eZContentClass::fetch( $userClassId ); $contentObject = $class->instantiate( 1, 1 ); $contentObjectId = $contentObject->attribute( 'id' ); //$contentObject->setAttribute( 'name', $login); $dataMap = $contentObject->dataMap(); foreach($dataTextAttributeList as $identifier=>$value) { $attribute = $dataMap[$identifier]; $attribute->setAttribute( 'data_text', $value); $attribute->sync(); } $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectId, 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $parentNodeId, 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1)); $nodeAssignment->store(); $version = $contentObject->version( 1 ); $version->setAttribute( 'status', 'EZ_VERSION_STATUS_DRAFT' ); $version->store(); $user = new eZUser( $contentObject->attribute( 'id' ) ); $user->setAttribute('login', $login ); $user->setAttribute('email', $email ); $hashType = eZUser::hashType() . ""; $newHash = $user->createHash( $login, $password, eZUser::site(), $hashType ); $user->setAttribute( "password_hash_type", $hashType ); $user->setAttribute( "password_hash", $newHash ); $user->store(); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectId, 'version' => 1 ) ); //assign section ... maybe there is a shorter way $object = eZContentObject::fetch( $contentObjectId, true); eZContentObjectTreeNode::assignSectionToSubTree( $contentObject->attribute( 'main_node_id' ), $sectionId ); return $user;}
//eg: create a new user under user group "Users" (node_id=5)$dataTextAttributeList = array('first_name'=>'Toto', 'last_name'=>'De La Motte');$oUser = createUser( 5, 4, 2, "toto", "toto@nospam.com", 'pass', $dataTextAttributeList );function createUser($parentNodeId, $userClassId, $sectionId, $login, $email, $password, $dataTextAttributeList){ $class = eZContentClass::fetch( $userClassId ); $contentObject = $class->instantiate( 1, 1 ); $contentObjectId = $contentObject->attribute( 'id' ); //$contentObject->setAttribute( 'name', $login); $dataMap = $contentObject->dataMap(); foreach($dataTextAttributeList as $identifier=>$value) { $attribute = $dataMap[$identifier]; $attribute->setAttribute( 'data_text', $value); $attribute->sync(); } $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObjectId, 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $parentNodeId, 'sort_field' => 2, 'sort_order' => 0, 'is_main' => 1)); $nodeAssignment->store(); $version = $contentObject->version( 1 ); $version->setAttribute( 'status', 'EZ_VERSION_STATUS_DRAFT' ); $version->store(); $user = new eZUser( $contentObject->attribute( 'id' ) ); $user->setAttribute('login', $login ); $user->setAttribute('email', $email ); $hashType = eZUser::hashType() . ""; $newHash = $user->createHash( $login, $password, eZUser::site(), $hashType ); $user->setAttribute( "password_hash_type", $hashType ); $user->setAttribute( "password_hash", $newHash ); $user->store(); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectId, 'version' => 1 ) ); //assign section ... maybe there is a shorter way $object = eZContentObject::fetch( $contentObjectId, true); eZContentObjectTreeNode::assignSectionToSubTree( $contentObject->attribute( 'main_node_id' ), $sectionId ); return $user;}
//eg: create a new user under user group "Users" (node_id=5)$dataTextAttributeList = array('first_name'=>'Toto', 'last_name'=>'De La Motte');$oUser = createUser( 5, 4, 2, "toto", "toto@nospam.com", 'pass', $dataTextAttributeList );

can someone help ?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.