001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.login;
020:
021: import java.io.IOException;
022:
023: import javax.mail.MessagingException;
024: import javax.mail.internet.AddressException;
025: import javax.portlet.ActionRequest;
026: import javax.portlet.ActionResponse;
027: import javax.portlet.PortletException;
028:
029: import com.nabhinc.portal.core.LocaleUtil;
030: import com.nabhinc.portal.core.PortalUtil;
031: import com.nabhinc.portal.model.PortalConfiguration;
032: import com.nabhinc.portal.spi.UserAdminServiceLocator;
033: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
034: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
035: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
036: import com.nabhinc.spi.NoSuchEntityException;
037: import com.nabhinc.spi.UserAdminService;
038: import com.nabhinc.util.EmailUtil;
039:
040: /**
041: *
042: *
043: * @author Padmanabh Dabke
044: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
045: */
046: public class SendUserName extends BaseRequestProcessor implements
047: ActionProcessor {
048:
049: public String process(ActionRequest request,
050: ActionResponse response, ActionConfig actionConfig)
051: throws PortletException, IOException {
052:
053: String userName = null;
054: String userEmail = request.getParameter("oemail");
055:
056: UserAdminService adminService = UserAdminServiceLocator
057: .getUserAdminService();
058: try {
059: userName = adminService.getUserNameFromEmail(userEmail);
060:
061: sendConfirmationEmail(request, userEmail, userName);
062:
063: } catch (NoSuchEntityException e) {
064: return "user-not-found";
065: } catch (AddressException e) {
066: return "invalid-address";
067: } catch (MessagingException e) {
068: this .brpLog.error(
069: "Failed to send username request email for user "
070: + userName, e);
071: return "email-failure";
072: }
073:
074: return "success";
075: }
076:
077: private void sendConfirmationEmail(ActionRequest request,
078: String emailAddress, String userName)
079: throws AddressException, MessagingException {
080:
081: PortalConfiguration pConfig = PortalConfiguration.getInstance();
082: String[] localeLabels = LocaleUtil
083: .getLocalizedStringArray(request.getLocale());
084:
085: String emailSubject = localeLabels[LocaleUtil.REQUEST_USERNAME_EMAIL_SUBJECT];
086:
087: String message = localeLabels[LocaleUtil.REQUEST_USERNAME_EMAIL_MESSAGE]
088: .replaceAll("\\$SERVER_URL", PortalUtil
089: .getPortalURLPrefix(request))
090: + localeLabels[LocaleUtil.REQUESTED_USERNAME]
091: + userName
092: + localeLabels[LocaleUtil.REQUESTED_USERNAME_EMAIL_NOTES]
093: + localeLabels[LocaleUtil.EMAIL_REGARDS];
094:
095: EmailUtil.send(pConfig.getPortalAdminEmail(), emailAddress,
096: emailSubject, message.toString());
097:
098: }
099:
100: }
|