001: /*
002: * ResetPassword.java
003: *
004: * Version: $Revision: 1.8 $
005: *
006: * Date: $Date: 2006/07/28 20:08:18 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.xmlui.aspect.eperson;
042:
043: import java.io.IOException;
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.Map;
047:
048: import org.apache.avalon.framework.parameters.Parameters;
049: import org.apache.cocoon.ProcessingException;
050: import org.apache.cocoon.environment.SourceResolver;
051: import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
052: import org.dspace.app.xmlui.wing.Message;
053: import org.dspace.app.xmlui.wing.WingException;
054: import org.dspace.app.xmlui.wing.element.Body;
055: import org.dspace.app.xmlui.wing.element.Division;
056: import org.dspace.app.xmlui.wing.element.Field;
057: import org.dspace.app.xmlui.wing.element.List;
058: import org.dspace.app.xmlui.wing.element.PageMeta;
059: import org.xml.sax.SAXException;
060:
061: /**
062: * Display a reset password form allowing the user to select a new password.
063: *
064: * @author Scott Phillips
065: */
066:
067: public class ResetPassword extends AbstractDSpaceTransformer {
068: /** Language strings */
069: private final static Message T_title = message("xmlui.EPerson.ResetPassword.title");
070:
071: private final static Message T_dspace_home = message("xmlui.general.dspace_home");
072:
073: private final static Message T_trail_forgot_password = message("xmlui.EPerson.trail_forgot_password");
074:
075: private final static Message T_head = message("xmlui.EPerson.ResetPassword.head");
076:
077: private final static Message T_para1 = message("xmlui.EPerson.ResetPassword.para1");
078:
079: private final static Message T_email_address = message("xmlui.EPerson.ResetPassword.email_address");
080:
081: private final static Message T_new_password = message("xmlui.EPerson.ResetPassword.new_password");
082:
083: private final static Message T_error_invalid_password = message("xmlui.EPerson.ResetPassword.error_invalid_password");
084:
085: private final static Message T_confirm_password = message("xmlui.EPerson.ResetPassword.confirm_password");
086:
087: private final static Message T_error_unconfirmed_password = message("xmlui.EPerson.ResetPassword.error_unconfirmed_password");
088:
089: private final static Message T_submit = message("xmlui.EPerson.ResetPassword.submit");
090:
091: private String email;
092: private java.util.List<String> errors;
093:
094: public void setup(SourceResolver resolver, Map objectModel,
095: String src, Parameters parameters)
096: throws ProcessingException, SAXException, IOException {
097: super .setup(resolver, objectModel, src, parameters);
098:
099: this .email = parameters.getParameter("email", "unknown");
100:
101: String errors = parameters.getParameter("errors", "");
102: if (errors.length() > 0)
103: this .errors = Arrays.asList(errors.split(","));
104: else
105: this .errors = new ArrayList<String>();
106:
107: }
108:
109: public void addPageMeta(PageMeta pageMeta) throws WingException {
110: // Set the page title
111: pageMeta.addMetadata("title").addContent(T_title);
112:
113: pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
114: pageMeta.addTrail().addContent(T_trail_forgot_password);
115: }
116:
117: public void addBody(Body body) throws WingException {
118:
119: Division register = body.addInteractiveDivision(
120: "reset-password", contextPath + "/register",
121: Division.METHOD_POST, "primary");
122:
123: register.setHead(T_head);
124:
125: EPersonUtils.forgottProgressList(register, 2);
126:
127: register.addPara(T_para1);
128:
129: List form = register.addList("form", List.TYPE_FORM);
130:
131: form.addLabel(T_email_address);
132: form.addItem(email);
133:
134: Field password = form.addItem().addPassword("password");
135: password.setRequired();
136: password.setLabel(T_new_password);
137: if (errors.contains("password")) {
138: password.addError(T_error_invalid_password);
139: }
140:
141: Field passwordConfirm = form.addItem().addPassword(
142: "password_confirm");
143: passwordConfirm.setRequired();
144: passwordConfirm.setLabel(T_confirm_password);
145: if (errors.contains("password_confirm")) {
146: passwordConfirm.addError(T_error_unconfirmed_password);
147: }
148:
149: form.addItem().addButton("submit").setValue(T_submit);
150:
151: register.addHidden("eperson-continue").setValue(knot.getId());
152: }
153:
154: }
|