<%@ page session="false" import="org.opencms.jsp.*,org.opencms.i18n.*" %><%

// get required OpenCms objects
CmsJspLoginBean cms = new CmsJspLoginBean(pageContext, request, response);

// read parameters from the request
String username = request.getParameter("username");
String password = request.getParameter("password");
String action = request.getParameter("action");
boolean action1 = Boolean.valueOf(request.getParameter("__loginform")).booleanValue();
String redirect = request.getParameter("requestedResource");
String login_project = cms.property("login_project", "search");
String login_redirect = cms.property("login_redirect", "search");


// now process the login data
if (action != null && "logout".equals(action)) 
{
	cms.logout();
	response.sendRedirect("/");
	return;
} 
else if (action != null && "login".equals(action)) 
{
	cms.login(username, password);
}

if (!cms.isLoggedIn()) 
{
// current user is not logged in - display the login form

	String message = "Please login:";
	if (!cms.isLoginSuccess()) 
	{
		// previous login attempt was not successful
		message = "Login failed, please try again:";
	}
%>
	<form action="<%= cms.getFormLink() %>" method="POST">
	<div>
		<input type="hidden" name="action" value="login" />
		<% 
			if (redirect != null)
		{
		%>
		<input type="hidden" name="requestedResource" value="<%= redirect %>" />
		<%
		}
		%>
		<h2><%= message %></h2>
		Username: <input name="username" size="25" tabindex="1" value="<%= username!=null?username:"" %>" />
		Password: <input name="password" size="25" tabindex="2" type="password" />
		<input type="submit" value="Login" />
	</div>
	</form>
<%
} 
else
{
	// current user is already logged in - display the logout form
	response.sendRedirect(redirect != null ? redirect : "/");
}
%>