[opencms-dev] Create a user through a jsp page with OpenCms6

Thomas Kiesl thomas.kiesl at bluemars.net
Tue Oct 24 10:04:24 CEST 2006


Hello Marc,

this page tries to get the values from the request. If you don't call 
this after with a post/get request from a form, you must set the values 
by userself:

Delete the validation:
 > // simple validation
 > if ( userName == null || "".equals(userName) ) {
 > throw new Exception( "User Name is required." );
 > } else if ( email == null || "".equals(email) ) {
 > throw new Exception( "Email is required." );
 > } else if ( password1 == null || "".equals( password1 ) ) { throw new
 > Exception( "Password is required." ); } else if ( password2 == null ||
 > "".equals( password2 ) ) { throw new Exception( "Password Again is
 > required." ); } else if ( email  == null || "".equals( email ) ) { throw
 > new Exception( "Email address must be valid." ); } else if (
 > !password1.equals( password2 )) { throw new Exception( "Passwords do not
 > match." ); } else if ( password1.length() < 7 ) { throw new Exception(
 > "Password must be at least 7 characters." ); } // Set default values for
 > optional params. if ( firstName == null ) { firstName = ""; }


And set the Values by userself:
String firstName = "Marc";
String lastName = "Fievet";
String userName = "mfievet;
String email = "marc at fievet.be";
String password1 = "secret";


Thats all

Thomas

Marc Fiévet wrote:
> Hello, 
> 
> I try this jsp on 6.2.2 but I have this return error code
> 
> "3 Oct 2006 17:55:36,484 ERROR [ina.core.ApplicationDispatcher: 704]
> "Servlet.service()" pour la servlet jsp a lancé une exception
> java.lang.Exception: User Name is required.
> 	at
> org.apache.jsp.WEB_002dINF.jsp.offline.sites.default_.user_jsp._jspServi
> ce(org.apache.jsp.WEB_002dINF.jsp.offline.sites.default_.user_jsp:70)
> 	at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 	at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
> va:322)
> 	at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
> 	at
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)"
> 
> 
> What's wrong? 
> 
> Thank you
> Regards,
> 
> MARC
> 
> 
> -----Message d'origine-----
> De : opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] De la part de Thomas Kiesl
> Envoyé : lundi 23 octobre 2006 16:16
> À : The OpenCms mailing list
> Objet : Re: [opencms-dev] Create a user through a jsp page with OpenCms6
> 
> 
> Hi Michele,
> 
> sorry the late answer. I hope this code will help you:
> 
> <%@ page session="false" %>
> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
> 
> <%@ page import="org.opencms.jsp.CmsJspActionElement,
> 	org.opencms.file.CmsObject,
> 	org.opencms.file.CmsUser,
> 	java.sql.*,
> 	java.io.*,
> 	java.util.Hashtable"
> %>
> <%
> String firstName = request.getParameter("fname");
> String lastName = request.getParameter("lname");
> String userName = request.getParameter("uname");
> String email = request.getParameter("email");
> String password1 = request.getParameter("pw1");
> String password2 = request.getParameter("pw2");
> String group = "Guests";
> CmsJspActionElement cmsjsp =
> new CmsJspActionElement( pageContext, request, response );
> 
> CmsObject cms = cmsjsp.getCmsObject();
> 
> // simple validation
> if ( userName == null || "".equals(userName) ) {
> throw new Exception( "User Name is required." );
> } else if ( email == null || "".equals(email) ) {
> throw new Exception( "Email is required." );
> } else if ( password1 == null || "".equals( password1 ) ) { throw new
> Exception( "Password is required." ); } else if ( password2 == null ||
> "".equals( password2 ) ) { throw new Exception( "Password Again is
> required." ); } else if ( email  == null || "".equals( email ) ) { throw
> new Exception( "Email address must be valid." ); } else if (
> !password1.equals( password2 )) { throw new Exception( "Passwords do not
> match." ); } else if ( password1.length() < 7 ) { throw new Exception(
> "Password must be at least 7 characters." ); } // Set default values for
> optional params. if ( firstName == null ) { firstName = ""; }
> 
> 
> 
> group = "Guests";
> 
> 
> if ( lastName == null ) {
> lastName = "";
> }
> // Hashtable for custom parameters
> Hashtable params = new Hashtable();
> params.put("test",new Timestamp(System.currentTimeMillis()));
> 
> CmsUser user = null;
> try {
> 	user = cms.addWebUser( userName, // Username
> 	password1, // Password
> 	group, // Default Group
> 	"Web User", // Comment
> 	params // Params Hashtable
> 	);
> 	user.setFirstname( firstName );
> 	user.setLastname( lastName );
> 	user.setEmail( email );
> 	cms.writeWebUser( user ); // Write changes to DB.
> }
> catch (Exception e) {
> 	e.printStackTrace(new PrintWriter(out));
> }
> %>
> 
> Best regards
> 
> Thomas
> 
> Bortolotti Michele wrote:
>> Hi everybody,
>> does enyone have ever had to create a User using jsp code? What 
>> classes
>> do I have to use?
>>  
>> Many thanks,
>> Michele.
>>
>>
>> ----------------------------------------------------------------------
>> --
>>
>>
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please 
>> visit http://lists.opencms.org/mailman/listinfo/opencms-dev
> 
> 


-- 
Mit freundlichen Grüßen

Thomas Kiesl

--
BLUE MARS - Gesellschaft fuer digitale Kommunikation mbH

Thomas Kiesl               mailto:thomas.kiesl at bluemars.net
Software Developer         http://www.bluemars.net
Ebersheimstraße 5          T +49.69.469973-0
60320 Frankfurt am Main    F +49.69.469973-99



More information about the opencms-dev mailing list