synyx GmbH & Co. KG Homepage Welcome Guest   | Login
  Search  
  Index  | Recent Threads  | Who's Online  | User List  | Register  | Search  | Help  | RSS feeds


Quick Go »
Thread Status: Normal
Total posts in this thread: 5
[Add To My Favorites] [Watch this Thread]
Author
Previous Thread This topic has been viewed 3982 times and has 4 replies Next Thread
Male MicheleBortolotti
Newbie



Joined: Sep 13, 2006
Posts: 24
Status: Offline

OpenCms 6 - How to create a user through a jsp page

Hi all,
I'm really scrumbling my head in order to create a user via a jsp page using the native OpenCms 6 (not 5!!) API (such as CmsUserDriver, CmsUser, etc).

I tried to use the method CmsUserDriver.createUser([u:11d43c9bf1]CmsDbContext dbc[/u:11d43c9bf1], java.lang.String name, java.lang.String password, java.lang.String description, java.lang.String firstname, java.lang.String lastname, java.lang.String email, long lastlogin, int flags, java.util.Map additionalInfos, java.lang.String address, int type) but when I have to pass the CmsDbContext parameter I really just don't know how to inizialize it; if I use the constructor CmsDbContext(CmsRequestContext context) I have so much further parameters to deal with (and I need the current db context, not an empty one).
I'm sure there is a very much simple method to create a user, but I really don't find it. :roll:

I hope someone here will be able to resolve this question. I'm sure this will be the right place to make a complete tutorial about this question.

Cheers,
Michele Bortolotti.
[Jan 1, 1990 12:01:00 AM] Show Printable Version of Post     [Link] Report threatening or abusive post: please login first  Go to top 
Female mbetti
Stranger



Joined: Sep 20, 2006
Posts: 7
Status: Offline


Take a look to org.opencms.file.CmsObject class. This is this method:

addWebUser(java.lang.String name, java.lang.String password, java.lang.String group, java.lang.String description, java.util.Map additionalInfos)

To creates a new web user.

If you need to create a principal user you can obtain using org.opencms.file.CmsUser construcor (simpler than your solution I think).
[Sep 22, 2006 12:12:02 PM] Show Printable Version of Post     [Link] Report threatening or abusive post: please login first  Go to top 
Male MicheleBortolotti
Newbie



Joined: Sep 13, 2006
Posts: 24
Status: Offline


 
Take a look to org.opencms.file.CmsObject class. This is this method:

addWebUser(java.lang.String name, java.lang.String password, java.lang.String group, java.lang.String description, java.util.Map additionalInfos)

To creates a new web user.

If you need to create a principal user you can obtain using org.opencms.file.CmsUser construcor (simpler than your solution I think).


Ok. The only problem is the constructor :roll:

In the first case:
CmsObject(CmsSecurityManager securityManager, CmsRequestContext context)
Ho do I have to initialize these two parameters in order to call the constructor?


Probably the second case is just what I need:
CmsUser(CmsUUID id, java.lang.String name, java.lang.String description)

Where CmsUUID is obtained calling the constructor CmsUUID() and then the method getOpenCmsUUID() that generate a UUID for OpenCms.

I will try and tell you :-)

Many thanks,
Michele.
[Jan 1, 1990 12:01:00 AM] Show Printable Version of Post     [Link] Report threatening or abusive post: please login first  Go to top 
Male MicheleBortolotti
Newbie



Joined: Sep 13, 2006
Posts: 24
Status: Offline


 
Take a look to org.opencms.file.CmsObject class. This is this method:

addWebUser(java.lang.String name, java.lang.String password, java.lang.String group, java.lang.String description, java.util.Map additionalInfos)

To creates a new web user.

If you need to create a principal user you can obtain using org.opencms.file.CmsUser construcor (simpler than your solution I think).


Hello,
I tried this, but I cannot see any new record inserted in the table cms_users:

import="org.opencms.file.CmsUser"
import="org.opencms.util.CmsUUID"

CmsUUID UUid = new CmsUUID();
out.println(UUid.toString());

CmsUser utente = new CmsUser(UUid, "JOHN CARPENTER", "DESCRIPTION");

utente.setEmail("email@email.com");
utente.setEnabled(true);

I don't get any error, but I don't see the new user through the Administration panel... i just guess why... :roll:
[Sep 25, 2006 9:40:40 AM] Show Printable Version of Post     [Link] Report threatening or abusive post: please login first  Go to top 
Male MicheleBortolotti
Newbie



Joined: Sep 13, 2006
Posts: 24
Status: Offline

Solution!

Here the solution, I hope you'll find it usefull :


<%@ page import="org.opencms.jsp.CmsJspActionElement,
org.opencms.file.CmsObject,
org.opencms.file.CmsUser,
java.util.Hashtable,
java.util.Map,
org.opencms.jsp.*"
%>


<%
//Read data sent from FORM
String firstName = request.getParameter("form_firstname");
String lastName = request.getParameter("form_lastname");
String userName = request.getParameter("form_username");
String email = request.getParameter("form_email");
String password1 = request.getParameter("form_password");
String password2 = request.getParameter("form_confirmPWD");
String userType = request.getParameter("form_user_type");


String group = "Guests";

java.util.Map additionalInfos;

CmsJspActionElement cmsjsp = new CmsJspActionElement(pageContext, request, response);

CmsObject cms = cmsjsp.getCmsObject();

// Hashtable for custom parameters
Hashtable params = new Hashtable();
additionalInfos = params;

if (userType.equals("WEB_USER"))
{
//WEB_USER
CmsUser user = cms.addWebUser(userName, password1, group, "Web User", additionalInfos);
user.setFirstname(firstName);
user.setLastname(lastName);
user.setEmail(email);

//Insert WEB_USER in cms_user table
cms.writeWebUser(user);

out.println("WEB_USER CREATED.");
}
else
{
//USER
CmsUser user = cms.createUser(userName, password1, "Web User", additionalInfos);
user.setFirstname(firstName);
user.setLastname(lastName);
user.setEmail(email);

//Insert USER in cms_user table
cms.writeUser(user);

out.println("USER CREATED.");
}

%>



Cheers,
Michele.
[Sep 25, 2006 5:26:26 PM] Show Printable Version of Post     [Link] Report threatening or abusive post: please login first  Go to top 
[Show Printable Version of Thread]