[opencms-dev] Creating users and login using JSP

Trevor Lee Trevor.Lee at 4Loop.com.au
Thu Nov 20 07:08:01 CET 2003


Hi,

Has anyone used JSP to create a new user and then used JSP to login as them
successfully?
The problem i'm having is that the user can be created and logged in using
JSP but when i goto the workflow and create a task the new user does not
appear in the group listing.

Please help as this is quite urgent for me.

This is the fragment of code to create the user:
    try
    {
        String slogin = cmso.loginUser("admin", "admin");
        out.println("logged in as: " + cms.user("name") + "<br/>");

        CmsUser user = cmso.addUser(sUsername, sPassword,
cmso.C_GROUP_PROJECTLEADER, "Project Manager", new Hashtable(),
cmso.C_FLAG_ENABLED);
        cmso.addUserToGroup(sUsername, cmso.C_GROUP_PROJECTLEADER);

        if (user == null)
            out.println("not created<br>");
        else
        {
            user.setEmail(sEmail);
            out.println(user.toString() + "<br>");
        }
    }
    catch (CmsException ce)
    {
        out.println("error");
        ce.printStackTrace(System.out);
   }

This is the code fragment to log in the user:
    CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
    CmsObject cmso = cms.getCmsObject();    String forward =
"/opencms/opencms/system/workplace/action/index.html";
    try
    {
        cmso.loginUser(username, password);
        cms = new CmsJspActionElement(pageContext, request, response);
        cms.init(pageContext, request, response);
        if (forward != null && !"".equals(forward))
            response.sendRedirect(forward);
        else
            out.println("You are now logged in as " + username);
    }
    catch (CmsException cmse)
    {
        out.println("<span class=\"errtext\">Invalid
Username/Password</span>");
    }

If any one can help ....
Thank you in advance

Trevor




More information about the opencms-dev mailing list