[opencms-dev] Create a user through a jsp page with OpenCms6
Dwayne Kristjanson
dwayne at realdecoy.com
Mon Oct 23 19:08:17 CEST 2006
The jsp is being accessed with a null or empty uname parameter and throwing an error. This is the expected behaviour if that jsp is either opened directly, or if the form that posts to it does not provide a valid username. The validation will need to be modified if you want it to do something other than throwing an exception when given invalid data.
(If you don't have a form that posts to this jsp, that would be the main problem. Create one that includes inputs for all of the request.getParameter("XXX") calls in the jsp. That will be enough to create users.)
--
Dwayne Kristjanson
-----Original Message-----
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Marc Fiévet
Sent: Monday, October 23, 2006 12:31 PM
To: 'The OpenCms mailing list'
Subject: RE : [opencms-dev] Create a user through a jsp page with OpenCms6
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
_______________________________________________
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
_______________________________________________
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
More information about the opencms-dev
mailing list