cancel
Showing results for 
Search instead for 
Did you mean: 

Create Users By Using Remote PHP-Apache System

samudaya
Champ on-the-rise
Champ on-the-rise
Hi,
I'm currently running Alfresco Community 3.4.d on Ubuntu 10.04 server. I want to create user accounts by using PHP module which runs on Apache web server (this should be separate physical server) . Anyone have achieved this so far? Could you please post the codes, configurations and relevant library files.

This is a grate help for me…… 

Thanks
15 REPLIES 15

ddanninger
Champ in-the-making
Champ in-the-making
hi there ,

download my library -> http://forge.alfresco.com/projects/ifresco-phplib/

i implemented some functions of the AdministrationService -> which can be found in Administration.php

there you find the method "createUser" …. also there is an UserDetails.php

So what you should do create a object by using the UserDetails then you should add the parameters to the UserDetails object like $object->cm_name and so on and then send it to the method of createUser in Administration.php

Thats not really nice implemented right now in the next versions of my ifresco phplibrary ill implement that.

samudaya
Champ on-the-rise
Champ on-the-rise
Hi friend,

Thank you very much for your help and contributions to open source.

I'm new to "ifresco". So it is great help if you could post a sample php code for create user by using "ifresco php library".

Thank you very much……..

samudaya
Champ on-the-rise
Champ on-the-rise
<?php
   $repositoryUrl = "http://myurl.com/alfresco/api";
   $userName = "admin";
   $password  = "adminpassword";

   // Include the required Alfresco PHP API objects 
   require_once "Alfresco/Service/Repository.php";
   require_once "Alfresco/Service/Session.php";
   require_once "Alfresco/Service/SpacesStore.php";
   require_once "Alfresco/Service/UserDetail.php";
   require_once "Alfresco/Service/Administration.php";


   // Authenticate the user and create a session
   $repository       = new Repository($repositoryUrl);
   $ticket          = $repository->authenticate($userName, $password);
   $session          = $repository->createSession($ticket);
   $store          = new SpacesStore($session);

   $new_admin_object   = new Administration($repository, $store, $session);   
   $my_user_details   = $new_admin_object->getUser("admin");         
       //This is perfectly work…………


/*
       //This is not working
   $new_user_object   = new UserDetail($session, $store, "userName=>newusername, password=>newpassword", $node=null, $id=null);
        $new_admin_object2   = new Administration($repository, $store, $session);   
        $my_user_details   = $new_admin_object2->createUser($new_user_object);

*/
?>

There is no "newUsers" in WSDL. I've changed it to "createUsers". But there are another errors.

Help me to solve this problem.  Could you please post a sample code for create user.

Thanks

samudaya
Champ on-the-rise
Champ on-the-rise
Finally solved the problem. Thanks all………….. Smiley Very Happy

   $repositoryUrl = "http://test.com:8080/alfresco/api";
   $userName = "admin";
   $password = "password";

   // Include the required Alfresco PHP API objects 
   require_once "Alfresco/Service/Repository.php";
   require_once "Alfresco/Service/Session.php";
   require_once "Alfresco/Service/SpacesStore.php";
   require_once "Alfresco/Service/UserDetail.php";
   require_once "Alfresco/Service/Administration.php";
   require_once "Alfresco/Service/NamedValues.php";

   // Authenticate the user and create a session
   $repository       = new Repository($repositoryUrl);
   $ticket          = $repository->authenticate($userName, $password);
   $session          = $repository->createSession($ticket);
   $spacesStore       = new SpacesStore($session);

   $administration = new Administration($repository,$spacesStore,$session);

   $NamedValues = new NamedValues($session);
   $NamedValues->cm_firstName = "FIRSTNAME";
   $NamedValues->cm_lastName = "LASTNAME";
   $NamedValues->cm_email = "EMAIL@EMAIL.COM";

   $userDetails = array("userName"=>"USERNAME",
   "password"=>"PASSWORD",
   "properties"=>$NamedValues->__toArray());

   print_r($administration->createUser($userDetails));

swiggy
Champ in-the-making
Champ in-the-making
Hello,
I installed ifresco library 0.2 and tested your code but I have this error :

Fatal error: Uncaught SoapFault exception: [Client] Function ("createUser") is not a valid method for this service in /home/vtiger510/www/alfresco_php/Alfresco/Service/WebService/AlfrescoWebService.php:65 Stack trace: #0 /home/vtiger510/www/alfresco_php/Alfresco/Service/WebService/AlfrescoWebService.php(65): SoapClient->__soapCall('createUser', Array, Array, Array, Array) #1 /home/vtiger510/www/alfresco_php/Alfresco/Service/WebService/AlfrescoWebService.php(47): AlfrescoWebService->__soapCall('createUser', Array) #2 [internal function]: AlfrescoWebService->__call('createUser', Array) #3 /home/vtiger510/www/alfresco_php/Alfresco/Service/Administration.php(76): AlfrescoWebService->createUser(Array) #4 /home/vtiger510/www/alfresco_php/examples/import_users/index.php(82): Administration->createUser(Array) #5 {main} thrown in /home/vtiger510/www/alfresco_php/Alfresco/Service/WebService/AlfrescoWebService.php on line 65‍

(The sample
SimpleBrowse
in the ifresco examples works like a charm).

Do you know where I can investigate ?
Thanks a lot

swiggy
Champ in-the-making
Champ in-the-making
Hello,
the functions queryUsers and getUser works, but createUser don't… any ideas ?
Thanks

ddanninger
Champ in-the-making
Champ in-the-making
I also already posted you the answer on the private message

in the ifresco client library 0.2 there is still this bug which samudaya reported:

So the fix is:

modify the Administration.php and go to line 75 + 76:

which is:

$result = $this->administrationService->newUsers(array(                            "createUsers" => $userDetails));‍‍

modify it to:

$result = $this->administrationService->createUsers(array(                            "newUsers" => $userDetails));‍‍

Not tested. please tell me if it worked

swiggy
Champ in-the-making
Champ in-the-making
Hello Dominik,
Thank you for your help, it works !

There's another small bug in Alfresco/Service/Repository.php line 45 that I corrected :

Line 45 :
   public function __construct($connectionUrl="http://localhost:8080/alfresco/api")‍‍

should be replaced by the url in config.php

and line 50

$this->_port = $parts["port"];‍

did not work with my url (https://www.url.net/alfresco/api). I hardcoded

$this->_port = 443;‍


By the way thanks for your work.
Regards

ddanninger
Champ in-the-making
Champ in-the-making
Ok thanks i will have a look on it 😃 and will fix it at 0.3 release