001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.apps.user; 029 030import org.opencms.db.CmsUserSettings; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsUser; 033import org.opencms.main.CmsException; 034import org.opencms.main.OpenCms; 035import org.opencms.notification.A_CmsNotification; 036import org.opencms.notification.CmsNotificationMacroResolver; 037import org.opencms.ui.login.CmsLoginHelper; 038import org.opencms.util.CmsMacroResolver; 039import org.opencms.workplace.CmsWorkplaceLoginHandler; 040 041/** 042 * Class to send email to user in case of password reset or creating new user.<p> 043 */ 044public class CmsSendPasswordNotification extends A_CmsNotification { 045 046 /** Field name. */ 047 private static final String FIELD_CHANGE_PASSWORD = "TextChangePassword"; 048 049 /** Field name. */ 050 private static final String FIELD_KEEP_PASSWORD = "TextKeepPassword"; 051 052 /**Is user new? */ 053 private boolean m_new; 054 055 /**Is password temporal? */ 056 private boolean m_tempPassword; 057 058 /** 059 * Public constructor.<p> 060 * 061 * @param cms CmsObject 062 * @param password password 063 * @param receiver User 064 * @param ou the user OU 065 * @param adminUser User 066 * @param newUser boolean 067 * @param tempPassword <code>true</code> to use a temporary password 068 */ 069 public CmsSendPasswordNotification( 070 CmsObject cms, 071 String password, 072 CmsUser receiver, 073 String ou, 074 CmsUser adminUser, 075 boolean newUser, 076 boolean tempPassword) { 077 078 super(cms, receiver); 079 m_new = newUser; 080 m_tempPassword = tempPassword; 081 addMacro("password", password); 082 String link = OpenCms.getLinkManager().getWorkplaceLink(cms, CmsWorkplaceLoginHandler.LOGIN_HANDLER, false) 083 + "?" 084 + CmsLoginHelper.PARAM_USERNAME 085 + "=" 086 + receiver.getSimpleName() 087 + "&" 088 + CmsLoginHelper.PARAM_OUFQN 089 + "=" 090 + receiver.getOuFqn(); 091 addMacro(CmsNotificationMacroResolver.WORKPLACE_LOGIN_LINK, "<a href =\"" + link + "\">" + link + "</a>"); 092 addMacro(CmsNotificationMacroResolver.RECEIVER_OU_FQN, ou); 093 try { 094 addMacro( 095 CmsNotificationMacroResolver.RECEIVER_OU, 096 OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, ou).getDisplayName( 097 new CmsUserSettings(receiver).getLocale())); 098 099 } catch (CmsException e) { 100 addMacro(CmsNotificationMacroResolver.RECEIVER_OU, receiver.getOuFqn()); 101 } 102 103 } 104 105 /** 106 * Public constructor.<p> 107 * 108 * @param cms CmsObject 109 * @param password password 110 * @param receiver User 111 * @param ou the user OU 112 * @param adminUser User 113 * @param link not used 114 * @param newUser boolean 115 * @param tempPassword <code>true</code> to use a temporary password 116 */ 117 @Deprecated 118 public CmsSendPasswordNotification( 119 CmsObject cms, 120 String password, 121 CmsUser receiver, 122 String ou, 123 CmsUser adminUser, 124 String link, 125 boolean newUser, 126 boolean tempPassword) { 127 128 this(cms, password, receiver, ou, adminUser, newUser, tempPassword); 129 130 } 131 132 /** 133 * @see org.opencms.notification.A_CmsNotification#appendXMLContent(java.lang.StringBuffer) 134 */ 135 @Override 136 protected void appendXMLContent(StringBuffer msg) { 137 138 String xmlName = m_tempPassword ? FIELD_CHANGE_PASSWORD : FIELD_KEEP_PASSWORD; 139 140 // append header from xmlcontent 141 msg.append( 142 CmsMacroResolver.resolveMacros(m_mailContent.getStringValue(m_cms, xmlName, m_locale), m_macroResolver)); 143 144 msg.append("\n<br/><br/>\n"); 145 146 // append footer from xmlcontent 147 msg.append( 148 CmsMacroResolver.resolveMacros(m_mailContent.getStringValue(m_cms, "Footer", m_locale), m_macroResolver)); 149 150 } 151 152 /** 153 * @see org.opencms.notification.A_CmsNotification#generateHtmlMsg() 154 */ 155 @Override 156 protected String generateHtmlMsg() { 157 158 return ""; 159 } 160 161 /** 162 * @see org.opencms.notification.A_CmsNotification#getNotificationContent() 163 */ 164 @Override 165 protected String getNotificationContent() { 166 167 if (m_new) { 168 return OpenCms.getSystemInfo().getConfigFilePath(m_cms, "notification/password-new-user-notification"); 169 } 170 return OpenCms.getSystemInfo().getConfigFilePath( 171 m_cms, 172 "notification/password-new-password-from-admin-notification"); 173 } 174 175}