HttpSession session = request.getSession();
UserObject userObject = (UserObject)session.getAttribute("userobject");
int individualID = userObject.getIndividualID(); // logged in user
ActionErrors allErrors = new ActionErrors();
DynaActionForm profileForm = (DynaActionForm)form;
EmailSettingsHome emailSettingsHome = (EmailSettingsHome)CVUtility.getHomeObject("com.centraview.administration.emailsettings.EmailSettingsHome","EmailSettings");
try {
EmailSettings emailSettingsRemote = (EmailSettings)emailSettingsHome.create();
emailSettingsRemote.setDataSource(dataSource);
// Its a predefined Template for the replying message for the Change Of user Information Information
EmailTemplateForm userInfoTemplateForm = emailSettingsRemote.getEmailTemplate(AdministrationConstantKeys.EMAIL_TEMPLATE_USER_PROFILE);
String toAddress = userInfoTemplateForm.getToAddress();
String fromAddress = userInfoTemplateForm.getFromAddress();
String replyTo = userInfoTemplateForm.getReplyTo();
String emailSubject = userInfoTemplateForm.getSubject();
String emailBody = userInfoTemplateForm.getBody();
MailMessageVO mailMessage = new MailMessageVO();
ArrayList toList = new ArrayList();
toList.add(toAddress);
mailMessage.setToList(toList);
mailMessage.setHeaders("Change Of User Information");
mailMessage.setContentType("text/plain");
mailMessage.setFromAddress(fromAddress);
mailMessage.setReplyTo(replyTo);
mailMessage.setSubject(emailSubject);
StringBuffer body = new StringBuffer("");
body.append(emailBody);
body.append("\n\nUser Information Change Request:\n\n");
DynaActionForm dynaForm = (DynaActionForm)form;
String entityName = (String)dynaForm.get("individualName");
body.append("Individual Name: " + entityName + "\n");
String title = (String)dynaForm.get("title");
body.append("Title: " + title + "\n");
String street1 = (String)dynaForm.get("street1");
body.append("Street1: " + street1 + "\n");
String street2 = (String)dynaForm.get("street2");
body.append("Street2: " + street2 + "\n");
String city = (String)dynaForm.get("city");
body.append("City: " + city + "\n");
String state = (String)dynaForm.get("state");
body.append("State: " + state + "\n");
String zipCode = (String)dynaForm.get("zipCode");
body.append("Zip Code: " + zipCode + "\n");
String country = (String)dynaForm.get("country");
body.append("Country: " + country + "\n");
String mocContent = "";
String mocTypeName = "";
if (dynaForm.get("email") != null) {
mocContent = (dynaForm.get("email") == null) ? "" : (String)dynaForm.get("email");
body.append("Email: " + mocContent + "\n");
}
for(int i=1 ; i<4 ; i++ ){
mocContent = CVUtility.getMOCContent(dynaForm, i+"");
int mocType = Integer.parseInt((String)dynaForm.get("mocType"+i));
mocTypeName = CVUtility.getSyncAs(mocType);
body.append(mocTypeName+": " + mocContent + "\n");
}
body.append("\n\n\nLogin Information Change Request:\n\n");
Integer userID = (Integer)dynaForm.get("userID");
body.append("UserID: " + userID.toString() +"\n");
String username = (String)dynaForm.get("username");
body.append("Username: " + username +"\n");
String oldPassword = (String)dynaForm.get("oldPassword");
body.append("Old Password: " + oldPassword + "\n");
String newPassword = (String)dynaForm.get("newPassword");
body.append("New Password: " + newPassword + "\n");
String newPasswordConf = (String)dynaForm.get("newPasswordConf");
body.append("Confirm Password: " + newPasswordConf + "\n");
body.append("\n\nEnd CentraView Web Request\n");
mailMessage.setBody(body.toString());
boolean messageSent = false;
try {
messageSent = emailSettingsRemote.simpleMessage(individualID,mailMessage);
} catch(Exception e) {
allErrors.add("error.customer.profile.emailSendFailure", new ActionMessage("error.customer.profile.emailSendFailure"));
saveErrors(request, allErrors);
//return(mapping.findForward(".view.customer.view_user"));
return(mapping.findForward(".view.customer.user_change_confirm"));
}
if (! messageSent) {
// if email message is not sent, let the user know we suck
allErrors.add("error.customer.profile.emailSendFailure", new ActionMessage("error.customer.profile.emailSendFailure"));
}
}catch(Exception e){
// if an exception occurs, then print a message to the log file,
// direct the user to the Customer Profile form, and show them
// an error.
logger.error("[Exception] UpdateUserHandler.Execute Handler ", e);
allErrors.add("error.unknownError", new ActionMessage("error.unknownError"));
forward = ".view.customer.view_user";
e.printStackTrace();
}
if (! allErrors.isEmpty()) {
// no point in saving errors to the request if there aren't any
saveErrors(request, allErrors);
}
return(mapping.findForward(forward));