bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
String action = RequestHelper.getString( "action", request );
String forwardUrl;
RequestDispatcher dispatcher;
HashMap<String, String> formErrors;
User user;
/* Load necessary lexicons */
bzb.getLexicon().load( "global" );
bzb.getLexicon().load( "register" );
bzb.getLexicon().load( "subject" );
/* Already logged in? */
if( bzb.getAuthenticatedUser( request ) != null ) {
forwardUrl = "/index";
}
/* Handle registration request */
else if( action.equals( "register" ) ) {
formErrors = checkRegistration( request );
/* No form errors, create the user and display validation page */
if( formErrors.isEmpty() ) {
user = createUser( request );
sendValidationEmail( user );
// @TODO remove below after email is working
request.setAttribute( "confirmCode", user.getValidationCode() );
forwardUrl = jspPath + "validationCode.jsp";
}
/* Show form errors */
else {
forwardUrl = jspPath + "register.jsp";
request.setAttribute( "formErrors", formErrors );
request.setAttribute( "countries", getCountries() );
}
}
/* Confirming an account */
else if( action.equals( "confirm" ) ) {
/* No email entered - display the form */
if( request.getParameter( "email" ) == null ) {
forwardUrl = jspPath + "validationCode.jsp";
request.setAttribute( "pageTitle", bzb.getLexicon().get( "confirmAccount" ) );
}
/* Code and email match - update user and display success */
else if( ( user = checkValidationCode( request ) ) != null ) {
forwardUrl = jspPath + "registerSuccess.jsp";
user.setValidated( true );
user.save();
request.setAttribute( "pageTitle", bzb.getLexicon().get( "registerSuccess" ) );
}
/* Show validation page with errors */
else {