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.controllers.membership;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.kernel.KernelConstants;
038: import org.libresource.kernel.LibresourceSecurityException;
039: import org.libresource.kernel.interfaces.KernelService;
040:
041: import org.libresource.membership.ejb.model.ProfileResourceValue;
042: import org.libresource.membership.interfaces.MembershipService;
043:
044: import org.libresource.web.Controller;
045: import org.libresource.web.config.Config;
046:
047: import java.net.URI;
048:
049: import java.util.Arrays;
050: import java.util.TimeZone;
051:
052: import javax.servlet.http.HttpServletRequest;
053: import javax.servlet.http.HttpServletResponse;
054:
055: public class EditProfileController implements Controller {
056: public Object process(URI uri, HttpServletRequest request,
057: HttpServletResponse response) throws Exception {
058: if (request.getParameter("cancel") != null) {
059: return uri;
060: }
061:
062: KernelService kernelService = (KernelService) Libresource
063: .getService(KernelConstants.SERVICE);
064:
065: if (!kernelService.checkSecurity(uri,
066: KernelConstants.SECURITY_UPDATE)) {
067: throw new LibresourceSecurityException(uri,
068: KernelConstants.SECURITY_UPDATE);
069: }
070:
071: MembershipService membershipService = (MembershipService) Libresource
072: .getService("Membership");
073: ProfileResourceValue user = membershipService.getProfile(uri);
074:
075: // init form
076: if (request.getParameter("name") == null) {
077: // lists
078: request.setAttribute("skins", Config.getInstance(null)
079: .listSkins());
080: request.setAttribute("langs", Config.getInstance(null)
081: .listLangs());
082:
083: String[] timeZones = TimeZone.getAvailableIDs();
084: Arrays.sort(timeZones);
085: request.setAttribute("timeZones", timeZones);
086: request.setAttribute("units", Config.getInstance(null)
087: .listUnits());
088:
089: request.setAttribute("login", user.getId());
090: request.setAttribute("name", user.getFullName());
091: request.setAttribute("email", user.getEmail());
092: request.setAttribute("jabber", user.getJabberId());
093:
094: return "/pages/modules/membership/editProfile.jsp";
095: }
096:
097: // process new values
098: String name = request.getParameter("name");
099:
100: if (name.trim().equals("")) {
101: name = user.getId();
102: }
103:
104: membershipService.editProfile(uri, name, request
105: .getParameter("email"), request.getParameter("jabber"));
106:
107: // lang
108: String lang = request.getParameter("lang");
109:
110: if (lang != null) {
111: membershipService.setUserInfo(uri, "libresource-web.lang",
112: lang);
113: }
114:
115: // skin
116: String skin = request.getParameter("skin");
117:
118: if (skin != null) {
119: membershipService.setUserInfo(uri, "libresource-web.skin",
120: skin);
121: }
122:
123: // timeZone
124: String timeZone = request.getParameter("timeZone");
125:
126: if (timeZone != null) {
127: membershipService.setUserInfo(uri,
128: "libresource-web.time-zone", timeZone);
129: }
130:
131: // unit
132: String unit = request.getParameter("unit");
133:
134: if (unit != null) {
135: membershipService.setUserInfo(uri, "libresource-web.unit",
136: unit);
137: }
138:
139: // authentification part
140: String newPass1 = request.getParameter("newpass1");
141: String newPass2 = request.getParameter("newpass2");
142:
143: if ((newPass1 != null) && (newPass2 != null)
144: && (newPass1.trim().length() > 0)
145: && (newPass2.trim().length() > 0)) {
146: if (newPass1.equals(newPass2)) {
147: membershipService.editCasUser(user.getId(), newPass1);
148:
149: if (kernelService.getConnectedResource().equals(
150: user.getUri())) {
151: request.getSession().setAttribute(
152: "security_password", newPass1);
153: }
154: }
155: }
156:
157: // clean cache
158: if (kernelService.getConnectedResource().equals(user.getUri())) {
159: request.getSession().removeAttribute("connectedUserCache");
160: }
161:
162: return uri;
163: }
164: }
|