Custom Login Page
Frontend login
A usual requirement for extension is to add an additional login form that allows for "frontend login". Frontend login means, that a user can login directly on the website without being brought to the OpenCms workplace. This is usually combined with Frontend Editing, where the user can edit pages directly from the website view, without having to enter the workplace.
A login form for this purpose will ask for login information, log the user into the system and bring him or her back to the page where they were before.
Sample Jsp Login File
The following JSP file will ask a user to log in.
If the form is submitted, the JSP code will attempt to log the user into the system. If that has been successful, the current project of that user is set to the "Offline" project and the site of the user is set to the default site ("/sites/default"). If all of this has been successful the user will be directed to a URL which was handed over to the login form by a URL parameter called url. If such a parameter was not handed over to the login form, then the user will be redirected to the index page.
frontendlogin.jsp
<%@ page session="true" import="org.opencms.main.*, org.opencms.jsp.*,org.opencms.file.*, java.lang.String" %><% CmsJspActionElement cms = new CmsJspActionElement(pageContext,request,response); String user = request.getParameter("user"); String password = request.getParameter("password"); String url = request.getParameter("url"); if( url==null || url.length()==0 || url.equalsIgnoreCase("null") ) url = "/index.html"; boolean loginFailed = false; //form was submitted => try to log in and redirect to given URl if((user!=null)