[opencms-dev] Login module

Jeff Greer jgreer at fdusa.com
Fri May 28 18:51:01 CEST 2004


Here is some JSP code that I use to login. It has a login form built in to it.
I have the file represented in my system as an elements file called login.jsp. Then I have a common template that I
use to define the layout of the site and include the login.jsp where I want it to show up. I use cascading style
sheets to define the look and feel of the form.

Hope this helps.

Cheers.



<%@ page session="true" %>
<%@ page import="java.util.*,com.opencms.core.*,org.opencms.jsp.*,org.opencms.file.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

<%
	CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
	CmsObject cmso = cms.getCmsObject();

	String username = request.getParameter("username");
	String password = request.getParameter("password");
	String logout = request.getParameter("logout");
	String login = request.getParameter("login");

	if("logout".equals(logout))
	{
		session.invalidate();
		cmso.loginUser("Guest", "");
		cms = new CmsJspActionElement(pageContext, request, response);
	}
	else if("login".equals(login))
	{
		try
		{
			cmso.loginUser(username, password);
			cms = new CmsJspActionElement(pageContext, request, response);
		}
		catch(org.opencms.security.CmsSecurityException e)
		{
			out.println("<script type=\"javascript\">alert(\"Login failed\n\" + e.getMessage());</script>");
		}
	}

	out.println("<p align=\"center\" class=\"login\">Member ID: " + cms.user("name") + "</p>");

	String form = "<form method=\"POST\">";

	if(cms.user("name").equals("Guest"))
	{
		form += "<table class=\"login\"><tr><td align=\"right\">" +
			"<label for=\"username\">Member ID:</label><br>" +
			"<input type=\"text\" id=\"username\" name=\"username\" size=\"9\"><br>" +
			"<label for=\"username\">Password:</label><br>" +
			"<input type=\"password\" id=\"password\" name=\"password\" size=\"9\">" +
			"</td></tr><tr><td align=\"right\">" +
			"<input type=\"submit\" name=\"login\" value=\"login\"></td></tr></table>";
	}
	else
	{
		form += "<input type=\"submit\" name=\"logout\" value=\"logout\">";
	}
	form += "</form>";
	out.println(form);
%>

Vlachogiannis Evangelos said:
> Hi all,
> I would like to know if there is a website login module.  Otherwise any help for building one?
>
> Thnx a lot,
> Vangelis
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev


-- 
Jeff Greer
Technical Support Consultant
Fretwell-Downing, Inc.
Phone: (913) 239-1214

The information transmitted in this electronic mail message may contain
confidential and or privileged materials.  For full details and restrictions
see http://www.fdgroup.com/emaildisclaimer.html






More information about the opencms-dev mailing list