001: /*
002: * StartForgotPassword.java
003: *
004: * Version: $Revision: 1.8 $
005: *
006: * Date: $Date: 2006/08/08 20:57:24 $
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.Item;
057: import org.dspace.app.xmlui.wing.element.List;
058: import org.dspace.app.xmlui.wing.element.PageMeta;
059: import org.dspace.app.xmlui.wing.element.Text;
060: import org.xml.sax.SAXException;
061:
062: /**
063: * Display the forgot password form, allowing the user to enter
064: * in an email address and have the system verify the email address
065: * before allowing the user to reset their password.
066: *
067: * There are two parameters that may be given to the form:
068: *
069: * email - The email of the forgotten account
070: *
071: * retry - A boolean value indicating that the previously entered email was invalid.
072: *
073: * @author Scott Phillips
074: */
075: public class StartForgotPassword extends AbstractDSpaceTransformer {
076: /** Language strings */
077: private final static Message T_title = message("xmlui.EPerson.StartForgotPassword.title");
078:
079: private final static Message T_dspace_home = message("xmlui.general.dspace_home");
080:
081: private final static Message T_trail_forgot_password = message("xmlui.EPerson.trail_forgot_password");
082:
083: private final static Message T_head = message("xmlui.EPerson.StartForgotPassword.head");
084:
085: private final static Message T_para1 = message("xmlui.EPerson.StartForgotPassword.para1");
086:
087: private final static Message T_email_address = message("xmlui.EPerson.StartForgotPassword.email_address");
088:
089: private final static Message T_email_address_help = message("xmlui.EPerson.StartForgotPassword.email_address_help");
090:
091: private final static Message T_error_not_found = message("xmlui.EPerson.StartForgotPassword.error_not_found");
092:
093: private final static Message T_submit = message("xmlui.EPerson.StartForgotPassword.submit");
094:
095: /** The email of the forgotten account */
096: private String email;
097:
098: /** A list of fields in error */
099: private java.util.List<String> errors;
100:
101: public void setup(SourceResolver resolver, Map objectModel,
102: String src, Parameters parameters)
103: throws ProcessingException, SAXException, IOException {
104: super .setup(resolver, objectModel, src, parameters);
105:
106: this .email = parameters.getParameter("email", "");
107:
108: String errors = parameters.getParameter("errors", "");
109: if (errors.length() > 0)
110: this .errors = Arrays.asList(errors.split(","));
111: else
112: this .errors = new ArrayList<String>();
113: }
114:
115: public void addPageMeta(PageMeta pageMeta) throws WingException {
116: // Set the page title
117: pageMeta.addMetadata("title").addContent(T_title);
118:
119: pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
120: pageMeta.addTrail().addContent(T_trail_forgot_password);
121: }
122:
123: public void addBody(Body body) throws WingException {
124:
125: Division forgot = body.addInteractiveDivision(
126: "start-forgot-password", contextPath + "/forgot",
127: Division.METHOD_POST, "primary");
128:
129: forgot.setHead(T_head);
130:
131: EPersonUtils.forgottProgressList(forgot, 1);
132:
133: forgot.addPara(T_para1);
134:
135: List form = forgot.addList("form", List.TYPE_FORM);
136:
137: Text email = form.addItem().addText("email");
138: email.setRequired();
139: email.setLabel(T_email_address);
140: email.setHelp(T_email_address_help);
141:
142: // Prefill with invalid email if this is a retry attempt.
143: if (email != null)
144: email.setValue(this .email);
145: if (errors.contains("email"))
146: email.addError(T_error_not_found);
147:
148: Item submit = form.addItem();
149: submit.addButton("submit").setValue(T_submit);
150:
151: forgot.addHidden("eperson-continue").setValue(knot.getId());
152: }
153:
154: /**
155: * Recycle
156: */
157: public void recycle() {
158: this.email = null;
159: super.recycle();
160: }
161: }
|