Hi,

Check http://code.xwiki.org/xwiki/bin/view/Snippets/Create200DummyUsersSnippet 
  for example.

A user is an object in xwiki.

Thanks
-Vincent

On Feb 2, 2009, at 6:51 PM, Juergen Lorenz Simon wrote:

> Hi,
>
> i'm trying to do a conceptually very, very simple task and find myself
> obscured to death by
> xwiki's data model (shall we call it one for now ...)
>
> After hitting my head on the lack of API for user, I somehow (dont ask
> me how) manage to
> assemble some code for creating a user. This CAN NOT be right?!
>
>                   Map map = Util.getObject(context.getRequest(),  
> "register");
>                   String content = "#includeForm(\"XWiki.XWikiUserSheet 
> \")";
>                   String template =
> context.getRequest().getParameter("template");
>                   String parent =
> context.getRequest().getParameter("parent");
>       
>                   if ("superadmin".equalsIgnoreCase(wikiname)) {
>                       log.error("Can't register user 'superadmin'. Name
> reserved.");
>                       return;
>                   }
>       
>                   try {
>                       if (!
> context.getUtil().match(context.getWiki().Param("xwiki.validusername",
> "/^[a-zA-Z0-9_]+$/"), wikiname)) {
>                           log.warn("Illegal username '"+wikiname+"'");
>                       }
>                   } catch (RuntimeException ex) {
>                       log.error("Invalid regular expression for
> xwiki.validusername", ex);
>                       if (!context.getUtil().match("/^[a-zA-Z0-9_]+$/",
> wikiname)) {
>                               log.error("Illegal username '"+wikiname+"'");
>                       }
>                   }
>       
>                   if ((template != null) && (!template.equals(""))) {
>                       XWikiDocument tdoc =
> context.getWiki().getDocument(template, context);
>                       if ((!tdoc.isNew())) {
>                           content = tdoc.getContent();
>                       }
>                   }
>       
>                   if ((parent == null) || (parent.equals(""))) {
>                       parent = "XWiki.XWikiUsers";
>                   }
>       
>                   // add password
>                   map.put("password", wikiname);
>                   map.put("active", "1");
>       
>                   if (log.isDebugEnabled()) {
>                       log.debug("Creating user with parameters:
> "+map.toString());
>                   }
>       
>                   int result = -1;
>                   try {
>                       result = context.getWiki().createUser(wikiname, map,
> parent, content, "edit", context);
>                       log.info("User " + xwikiUser + " created  
> successfully.");
>                       userSuccessful = true;
>                   } catch (Exception e) {
>                       log.error("Exception when creating user "+wikiname,e);
>                   }
>       
>                   if (result!=1) {
>                       log.error("Creating user " + xwikiUser + " has failed
> with status "+result);
>                   }
>
> Is this REALLY necessary? The task of creating a new user can be
> achieved easier, surely?
>
> Now I did have some code for checking if a given group exists, if not
> create it. Then check if the user is in the group
> and of not, add him. All my attempts in this direction were rewarded
> with frustration. I find the data model (or perhaps
> the abscence of cleaner structure for these things) highly obscure and
> impossible to penetrate without a proper form
> of documentation.
>
> Does such documentation exist? A few simple examples perhaps?
>
> Best Regards,
> J.L.Simon

Thanks
-Vincent
http://xwiki.com
http://xwiki.org
http://massol.net






_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to