001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.servlets;
034:
035: import org.libresource.Libresource;
036: import org.libresource.LibresourceException;
037:
038: import org.libresource.membership.MembershipConstants;
039: import org.libresource.membership.interfaces.MembershipService;
040:
041: import org.libresource.web.config.Config;
042:
043: import javax.servlet.http.HttpServletRequest;
044: import javax.servlet.http.HttpServletResponse;
045:
046: public class CreateUser extends BaseServlet {
047: protected void process(HttpServletRequest request,
048: HttpServletResponse response) throws Exception {
049: if (!Config.getInstance(null).canRegisterUser()) {
050: request.setAttribute("createError",
051: "You cannot create new account on this platform.");
052: request.getRequestDispatcher(
053: "/pages/modules/membership/createUser.jsp")
054: .forward(request, response);
055:
056: return;
057: }
058:
059: if (request.getParameter("login") == null) {
060: request.getRequestDispatcher(
061: "/pages/modules/membership/createUser.jsp")
062: .forward(request, response);
063:
064: return;
065: }
066:
067: if (!request.getParameter("repass").equals(
068: request.getParameter("pass"))) {
069: request.setAttribute("createError",
070: "Password confirmation is incorrect");
071: }
072:
073: if (request.getParameter("pass").trim().equals("")) {
074: request.setAttribute("createError", "Password is required");
075: }
076:
077: if (request.getParameter("login").trim().equals("")) {
078: request.setAttribute("createError", "Login is required");
079: }
080:
081: if (request.getAttribute("createError") != null) {
082: request.getRequestDispatcher(
083: "/pages/modules/membership/createUser.jsp")
084: .forward(request, response);
085:
086: return;
087: }
088:
089: try {
090: MembershipService membershipService = (MembershipService) Libresource
091: .getService(MembershipConstants.SERVICE);
092: membershipService.createCasUser(request
093: .getParameter("login"), request
094: .getParameter("pass"));
095: } catch (LibresourceException e) {
096: request.setAttribute("createError", e.getMessage());
097: request.getRequestDispatcher(
098: "/pages/modules/membership/createUser.jsp")
099: .forward(request, response);
100:
101: return;
102: }
103:
104: request.getRequestDispatcher("/Login").forward(request,
105: response);
106: }
107: }
|