1/*2 * Copyright 2000-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.modules.actions;
1819// Java stuff20import java.io.StringWriter;
21import java.util.Properties;
2223// Jetspeed Stuff24import org.apache.jetspeed.services.TemplateLocator;
25import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
26import org.apache.jetspeed.services.logging.JetspeedLogger;
27import org.apache.jetspeed.services.resources.JetspeedResources;
28import org.apache.jetspeed.services.JetspeedSecurity;
29import org.apache.jetspeed.om.security.JetspeedUser;
3031// Turbine Stuff32import org.apache.turbine.modules.Action;
33import org.apache.turbine.services.localization.Localization;
34import org.apache.turbine.services.velocity.TurbineVelocity;
35import org.apache.turbine.util.RunData;
36import org.apache.turbine.util.DynamicURI;
37import org.apache.turbine.util.mail.SimpleEmail;
3839// Velocity Stuff40import org.apache.velocity.context.Context;
4142/***43 * This action will attempt to send a confirmation email to the user.44 * This class is used in two places, the first one is for new users.45 * The second is where a user is updating their information after they 46 * have already created their account. If they are updating and they change 47 * their email address, then we want to re-confirm it to prevent people from 48 * screwing up their email address.49 *50 *@author <a href="mailto:paulsp@apache.org">Paul Spencer</a>51 */52publicclassSendConfirmationEmailextends Action
53 {
5455/***56 * Static initialization of the logger for this class57 */58privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(SendConfirmationEmail.class.getName());
5960publicvoid doPerform( RunData data ) throws Exception
61 {
62JetspeedUser user = JetspeedSecurity.getUser(data.getParameters().getString("username", ""));
63 DynamicURI url = new DynamicURI(data)
64 .addPathInfo(JetspeedResources.PATH_TEMPLATE_KEY, "ConfirmRegistration")
65 .addPathInfo("username", user.getUserName())
66 .addPathInfo("secretkey", user.getConfirmed())
67 .addPathInfo("password", user.getPassword());
68try69 {
70//build body via template71 StringWriter email_body = new StringWriter();
72 Context emailContext = TurbineVelocity.getContext(data);
73 SimpleEmail se = new SimpleEmail();
74 emailContext.put( "data", data );
75 emailContext.put( "user", user );
76 emailContext.put("config",newJetspeedResources());
77 emailContext.put("urltojetspeed",url);
78 emailContext.put("email",se);
79 String templateFile = JetspeedResources.getString("newuser.confirm.email.template");
80 String templatePath = TemplateLocator.locateEmailTemplate(data, templateFile);
81 TurbineVelocity.handleRequest(emailContext, templatePath, email_body);
8283 se.setMsg( email_body.toString() );
8485 Properties props = System.getProperties();
86 String mailServerMachine = JetspeedResources.getString( "mail.server" );
87 props.put ( "mail.host", mailServerMachine );
88 props.put("mail.smtp.host", mailServerMachine);
8990 se.send();
9192 data.setMessage (Localization.getString(data, "SENDCONFIRMATIONEMAIL_SENT"));
93 }
94catch ( Exception e )
95 {
96 String errorTitle = Localization.getString("SENDCONFIRMATIONEMAIL_ERROR") ;
97 String errorMessage = errorTitle + e.getMessage();
9899 logger.error( errorMessage, e );
100 data.setMessage ( errorTitle + errorMessage );
101 }
102 }
103 }