Hi Edd,

Here is the code used in our register new user engine.

               JahiaUser newUser = ServicesRegistry.getInstance().
                                   getJahiaUserManagerService().
                                   createUser(userName,
                                              password1,
                                              userName + ":" +
                                              Integer.toString(jParams.
                   getSiteID()),
                                              jParams.getSiteID(),
                                              userProperties);
               if (newUser != null) {
                   ServicesRegistry.getInstance().
                       getJahiaSiteUserManagerService().addMember(jParams.
                       getSiteID(), newUser);

// make user part of selected groups.
if ((groupList != null) && (groupList.length > 0)) {
for (int i = 0; i < groupList.length; i++) {
JahiaGroup curGroup = ServicesRegistry.getInstance().
getJahiaGroupManagerService().
lookupGroup(
jParams.getSiteID(), groupList[i]);
if (curGroup != null) {
curGroup.addMember(newUser);
}
}
}
}


Note the adding of the user to the SiteUserManagerService which handles user sharing between sites.

Also, if something is failing silently, you might want to increase the logging level of your Jahia installation to see if it tells you why the new user isn't getting created (maybe the user already exists ?)

Regards,
 Serge Huber.

Edd Dawson wrote:

Hi,

I'm trying to create a new Jahia user from within a jahia page visible only to the root user.

This is the code I've used:

String name = "harvey";
String password = "harvey";
Properties properties = new Properties();
properties.setProperty("firstname", "Harvey");
properties.setProperty("lastname", "Rabbit");
properties.setProperty("email", "[EMAIL PROTECTED]");
JahiaUserManagerRoutingService userService =
                JahiaUserManagerRoutingService.getInstance();
JahiaUser newUser = userService.createUser(name, password,
                                          name + ":1",
                                          jData.params().getSiteID(),
                                          properties);

No errors are thrown when the page is viewed but newUser is always null.

I've tried several variations on the code (including adding the ":1" to both name and userKey and leaving it off both), but the result is always a null value in the user variable, and no new user appears in the user administration list.

Any suggestions?

cheers
Edd




Reply via email to