KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > validation > LoginEmailValidator


1 /* ====================================================================
2 * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3 *
4 * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. The end-user documentation included with the redistribution,
19 * if any, must include the following acknowledgment:
20 * "This product includes software developed by Jcorporate Ltd.
21 * (http://www.jcorporate.com/)."
22 * Alternately, this acknowledgment may appear in the software itself,
23 * if and wherever such third-party acknowledgments normally appear.
24 *
25 * 4. "Jcorporate" and product names such as "Expresso" must
26 * not be used to endorse or promote products derived from this
27 * software without prior written permission. For written permission,
28 * please contact info@jcorporate.com.
29 *
30 * 5. Products derived from this software may not be called "Expresso",
31 * or other Jcorporate product names; nor may "Expresso" or other
32 * Jcorporate product names appear in their name, without prior
33 * written permission of Jcorporate Ltd.
34 *
35 * 6. No product derived from this software may compete in the same
36 * market space, i.e. framework, without prior written permission
37 * of Jcorporate Ltd. For written permission, please contact
38 * partners@jcorporate.com.
39 *
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This software consists of voluntary contributions made by many
55 * individuals on behalf of the Jcorporate Ltd. Contributions back
56 * to the project(s) are encouraged when you make modifications.
57 * Please send them to support@jcorporate.com. For more information
58 * on Jcorporate Ltd. and its products, please see
59 * <http://www.jcorporate.com/>.
60 *
61 * Portions of this software are based upon other open source
62 * products and are subject to their respective licenses.
63  */

64 package com.jcorporate.expresso.services.validation;
65
66 import com.jcorporate.expresso.core.controller.Controller;
67 import com.jcorporate.expresso.core.controller.ControllerException;
68 import com.jcorporate.expresso.core.controller.ControllerRequest;
69 import com.jcorporate.expresso.core.controller.ControllerResponse;
70 import com.jcorporate.expresso.core.controller.NonHandleableException;
71 import com.jcorporate.expresso.core.controller.Transition;
72 import com.jcorporate.expresso.core.db.DBException;
73 import com.jcorporate.expresso.core.i18n.Messages;
74 import com.jcorporate.expresso.core.misc.StringUtil;
75 import com.jcorporate.expresso.core.security.User;
76 import com.jcorporate.expresso.services.dbobj.Setup;
77
78 import java.util.Hashtable JavaDoc;
79 import java.util.Vector JavaDoc;
80
81
82 /**
83  * This class is a helper class that allows the LoginController controller to
84  * validate the email address provided as part of express registration.
85  *
86  * @author Shash Chatterjee
87  * @version $Revision: 1.17 $ $Date: 2004/11/17 20:48:22 $
88  * @see com.jcorporate.expresso.services.controller.LoginController
89  */

90 public class LoginEmailValidator implements ValidationHandler {
91     /**
92      * Default constructor Creation date: (9/23/2001 2:23:06 PM) Author: Shash
93      * Chatterjee
94      */

95     public LoginEmailValidator() {
96         super();
97     }
98
99     /**
100      * This method is used to send the user that registered an email so that
101      * when they click on the link it can be verified that the email address
102      * they provided does indeed belong to them and is a working email
103      * address. This method is called by ValidationJob when a new validation
104      * request is submitted. Creation date: (9/23/2001 2:24:30 PM) Author:
105      * Shash Chatterjee
106      *
107      * @param params params All the application-specific parameters from
108      * LoginController
109      * @param URL URL The link that the user will click on to validate the
110      * request
111      * @throws AuthValidationException AuthValidationException
112      * @see com.jcorporate.expresso.services.job.ValidationJob
113      */

114     public void notify(Hashtable JavaDoc params, String JavaDoc URL)
115             throws AuthValidationException {
116         // The db context for the user (Note: this is different from the Validation entry context, which
117
// could very well be in a different DB context)
118
String JavaDoc dbName = (String JavaDoc) params.get("db");
119
120         // The login name of the user
121
String JavaDoc loginName = (String JavaDoc) params.get("UserName");
122
123         try {
124             // Check that user with login name actually exists
125
User myUser = new User();
126             myUser.setDataContext(dbName);
127             myUser.setLoginName(loginName);
128
129             if (!myUser.find()) {
130                 throw new AuthValidationException("User with login \"" +
131                         loginName + "\" not found");
132             }
133
134             // Create the list of addresses to notify, in this case just the user
135
Vector JavaDoc addresses = new Vector JavaDoc(0);
136             addresses.add(myUser.getEmail());
137
138             Object JavaDoc[] args = {
139                 loginName, URL, Setup.getValue(dbName, "CompanyName"),
140                 Setup.getValue(dbName, "HomePageURL")
141             };
142
143             // Send email notification
144
ValidationEntry.notifyByEmail(dbName,
145                     Setup.getValue(dbName, "MAILFrom"), addresses,
146                     getString("loginReqSubject"), getString("loginReqEM1", args));
147         } catch (DBException dbe) {
148             throw new AuthValidationException("DB error accessing user \"" +
149                     loginName + "\"", dbe);
150         }
151     }
152
153     /**
154      * This method is used to transition back to the "emailValidate" state of
155      * the registration controller which then completes the user's
156      * registration and sends out the email notification of succesful
157      * registration. This method is called by ValidationController after a
158      * validation code matches that stored in the validation entry. Creation
159      * date: (9/23/2001 2:24:30 PM) Author: Shash Chatterjee
160      *
161      * @param params All the application-specific parameters from
162      * LoginController
163      * @param request the ControllerRequest object
164      * @param response The controller response from the runValidationState of
165      * ValidationController
166      * @param ctlr The ValidationController instance
167      * @return ControllerResponse
168      * @throws ControllerException upon error
169      * @throws NonHandleableException upon fatal error
170      * @see com.jcorporate.expresso.services.controller.ValidationController
171      */

172     public ControllerResponse validated(Hashtable JavaDoc params,
173                                         ControllerRequest request, ControllerResponse response, Controller ctlr)
174             throws ControllerException, NonHandleableException {
175         // The db context for the user (Note: this is different from the Validation entry context, which
176
// could very well be in a different DB context)
177
String JavaDoc dbname = (String JavaDoc) params.get("db");
178
179         // The login name of the user
180
String JavaDoc loginName = (String JavaDoc) params.get("UserName");
181
182         String JavaDoc registrationController = (String JavaDoc) params.get("RegistrationController");
183         String JavaDoc loginController = (String JavaDoc) params.get("LoginController");
184
185         StringUtil.assertNotBlank(registrationController,
186                 "Error - Email Validator needed registration controller parameter");
187
188         StringUtil.assertNotBlank(loginController,
189                 "Error - Email Validator needed login controller parameter");
190
191         Transition t = new Transition();
192         t.setControllerObject(registrationController);
193         t.setState("emailValidate");
194         t.setName("emailValidate");
195         t.addParam("db", dbname);
196         t.addParam("UserName", loginName);
197         t.addParam("LoginController", loginController);
198         t.addParam("RegistrationController", registrationController);
199
200         //We redirect transition so that the user's URL changes
201
t.redirectTransition(request, response);
202
203         return response;
204     }
205
206     /**
207      * Convenience version of the above with no arguments.
208      *
209      * @param stringCode the string to localize
210      * @return The local-language string corresponding to the given code to
211      * return the local language by considering the user as well.
212      */

213     protected String JavaDoc getString(String JavaDoc stringCode) {
214         Object JavaDoc[] args = {};
215
216         return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema",
217                 stringCode, args);
218     }
219     /* getString(String) */
220
221     /**
222      * Pass on a call to retrieve an appropriate localized string from the
223      * correct Schema object. This version of the call is overridden with more
224      * sophisticated versions in DBController (which knows the username)
225      *
226      * @param stringCode the string to localize
227      * @param args formatting arguments
228      * @return java.lang.String to return the local language by considering the
229      * user as well.
230      */

231     protected String JavaDoc getString(String JavaDoc stringCode, Object JavaDoc[] args) {
232         return Messages.getString("com.jcorporate.expresso.core.ExpressoSchema",
233                 stringCode, args);
234     }
235     /* getString(String, Object[]) */
236 }
237
Popular Tags