[opencms-dev] understanding CmsJspLoginBean
Christoph P. Kukulies
kuku at physik.rwth-aachen.de
Wed Apr 25 12:53:41 CEST 2007
In my login.jsp I'm using:
<jsp:useBean id="loginBean" class="org.opencms.jsp.CmsJspLoginBean">
<%
loginBean.init(pageContext,request,response);
if(request.getParameter("username")!= null){
loginBean.login(request.getParameter("username"),request.getParameter("password"),null,
request.getParameter("requestedResource"));
out.write("Username: "+request.getParameter("username"));
}
%>
</jsp:useBean>
<%
String username=request.getParameter("username");
if(!loginBean.isLoggedIn()) {
if(!loginBean.isLoginSuccess()){
out.write("login failed!");
}
%>
<h3>Mitgliederbereich</h3>
<p><span>Dieser Bereich ist ausschließlich den Mitgliedern
vorbehalten. Wenn Sie bereits registriert sind, dann loggen Sie sich
bitte hier ein:</span> </p>
<p><span> </span> </p>
<form method="GET" action="verlogin.jsp">
<input type="hidden" name="requestedResource" value="<%=
request.getParameter("requestedResource")%>">
<p> <label class="left">Benutzername/Mitgliedsnummer</label> <input
type="text" name="username"
size="10"value="<%=(username!=null)?username:"" %>"/> <br />
<label class="left">Kennwort</label> <input type="password"
name="password" size="10" /> <input type="submit" value="login" /></p>
</form>
In the footer (foot.jsp) I have
<%
CmsJspActionElement jsp = new CmsJspActionElement(pageContext,
request,response);
String username =
jsp.getCmsObject().getRequestContext().currentUser().getName();
%>
<c:set var="locale"><cms:property name="locale" file="search"/></c:set>
<fmt:setLocale value="${locale}"/>
<fmt:bundle basename="messages">
<cms:template element="foot">
<div id="footer"><div class="left">
<a href="<cms:link>/de/Impressum/index.htm</cms:link>">Impressum</a><%
if(!username.equals(null)) {
out.write("Sie sind eingeloggt als ["+username+"] "); %> <a
href="/system/modules/org.myorg.frontend/pages/logout.jsp">Ausloggen</a><%
} %></div>
<div id="fussnoterechts"><a href="#" id="nachoben">nach
oben</a></div></div>
</cms:template>
</fmt:bundle>
Now what code comes into logout.jsp?
Do I refer the loginBean with ID=loginBean there? Is the loginBean a
unique servlet (storage area?) for the session which I can refer
everywhere?.
I'm getting an exception at the moment when I invoke the logout()
message of the login bean and the docs say it thwos an exception
when the redirect after the logout fails.
How would logout.jsp have to look like?
At present it looks like this:
<%@ page session="false" import="java.util.*,org.opencms.jsp.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<jsp:useBean id="loginBean" class="org.opencms.jsp.CmsJspLoginBean">
<%
out.write("User "+loginBean.getUserName()+ " logged out");
loginBean.logout();
%>
</jsp:useBean>
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
More information about the opencms-dev
mailing list