HowTo: Implement a Login Form and Register Page

The login is handled by the login module (from the Core package) while the registration is found in the usermanager? module (Core package).

Implementation of the login

To add a login form on a page simply use this code

    <form method="post" action="login.jsp">
      Name: <input name="Login_username" /><br/>
      Password: <input name="Login_userauth" type="password" /><br/>
      <input class="button" type="submit" name="Login_createEntry" value="login" /> 
    </form>

a typical login.jsp could look like this:

<%@ page language="java" import="corinis.*,corinis.modules.*,corinis.util.*" %>
<%
Core core = new Core (pageContext);
Login login = (Login)core.getModule(Login.class);
login.deleteEntry();
login.createEntry();
%>
<html>
<body>
<%
if (core.isLoggedOn())
{
%>
Thanks for logging in!
<%
}
else
{
%>
You are not logged in.... Make sure to enter the correct password or <a href="register.jsp">register</a>
<%
}
%>
</body>
</html>

Autologin

If you want to add autologin (or a "remember me" feature) to your web application (so users don't have to enter their username/password after they closed the browser) change the form so it sends Login_remember (see Modules/Login) and call the createAutoLogin function of the Login module.

This snipped adds a checkbox, so users can choose if they want to be remembered or not (checked per default):

    <form method="post" action="login.jsp">
      Name: <input name="Login_username" /><br/>
      Password: <input name="Login_userauth" type="password" /><br/>
      <input name="Login_remember" value="true" checked="checked" type="checkbox"/> remember me<br/>
      <input class="button" type="submit" name="Login_createEntry" value="login" /> 
    </form>

a typical login.jsp with auto-login feature could look like this:

<%@ page language="java" import="corinis.*,corinis.modules.*,corinis.util.*" %>
<%
Core core = new Core (pageContext);
Login login = new Login(core);
login.deleteEntry();
login.createEntry();

// autologin:
login.createAutoLogin();

%>
<html>
<body>
<%
if (core.isLoggedOn())
{
%>
Thanks for logging in!
<%
}
else
{
%>
You are not logged in.... Make sure to enter the correct password or <a href="register.jsp">register</a>
<%
}
%>
</body>
</html>

Register

Each user in corinis has:

  • a core profile consisting of username/password and an optional email address (depending on your configuration user might have to register with an email address and verification)
  • one or more authority-groups

Each user in corinis could have:

  • a custom profile (profiler)

The module that handles the registration is the UserManager?.

registration without profile

A basic registration form looks like this:

<form name="register" action="doRegister.jsp" method="post">
Name: <input name="UserManager_localusername" />
E-Mail: <input name="UserManager_email" />
Password: <input name="UserManager_localuserauth" type="password" />
verify password: <input name="UserManager_localuserauthconf" type="password" />
</form>

The registration is done with following jsp:

<%@ page language="java" import="corinis.*,corinis.modules.*,corinis.util.*" %>
<%
Core core = new Core (pageContext);
UserManager um = (UserManager)core.getModule(UserManager.class);
out.println(core.parseDom(um.createEntry(), "show.xsl"));
%>

You should create an xsl, that handles possible errors (like "User already Exists" or "Field missing") - see ErrorMessages

The profile

If you want users to have a profile, you have to create the profile fields in the profiler (Core->Profiler in the administration). Each field can be assigned with a regular expression which will be used to check if the user has entered a correct value.

After you are finished with the definition you just add a form-field to the registration form:

...
<input name="UserManager_NameOfTheProfileField"/>
Pet: <input name="UserManager_pet"/>
...