Author: jleroux
Date: Sat Apr  7 09:17:41 2012
New Revision: 1310716

URL: http://svn.apache.org/viewvc?rev=1310716&view=rev
Log:
Followed Scott"s suggestion and added a generic EMAIL_PASSWORD 
EmailTemplateSetting (used to send a new password at user request)
I finally kept also the previous way because it allow an easier 18n of at the 
email subject.

Still the same concern: OOTB, if the user has not set a SMPT server in 
general.properties for the defaultFromEmailAddress the message "A new password 
has been created and sent to you. Please check your Email." when actually 
nothing happens. But that's anyway user's responsibility

Modified:
    ofbiz/trunk/applications/securityext/data/UserDemoData.xml
    
ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
    ofbiz/trunk/framework/common/config/SecurityextUiLabels.xml

Modified: ofbiz/trunk/applications/securityext/data/UserDemoData.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/securityext/data/UserDemoData.xml?rev=1310716&r1=1310715&r2=1310716&view=diff
==============================================================================
--- ofbiz/trunk/applications/securityext/data/UserDemoData.xml (original)
+++ ofbiz/trunk/applications/securityext/data/UserDemoData.xml Sat Apr  7 
09:17:41 2012
@@ -78,5 +78,8 @@ under the License.
     <UserLogin userLoginId="ltdadmin" partyId="ltdadmin"/>
     <UserLogin userLoginId="ltdadmin1" partyId="ltdadmin1"/>
     <UserLogin userLoginId="bizadmin" partyId="bizadmin"/>
+    
+    <EmailTemplateSetting emailTemplateSettingId="EMAIL_PASSWORD" subject="New 
Password Sent (${userLoginId})" fromAddress="[email protected]"
+        description="Used to send a new password at user request"/>
 
 </entity-engine-xml>

Modified: 
ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java?rev=1310716&r1=1310715&r2=1310716&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
 (original)
+++ 
ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/login/LoginEvents.java
 Sat Apr  7 09:17:41 2012
@@ -37,11 +37,13 @@ import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.common.login.LoginServices;
 import org.ofbiz.base.crypto.HashCrypt;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtilProperties;
 import org.ofbiz.party.contact.ContactHelper;
 import org.ofbiz.product.product.ProductEvents;
 import org.ofbiz.product.store.ProductStoreWorker;
@@ -284,8 +286,21 @@ public class LoginEvents {
             serviceContext.put("sendBcc", productStoreEmail.get("bccAddress"));
             serviceContext.put("contentType", 
productStoreEmail.get("contentType"));
         } else {
-            serviceContext.put("subject", UtilProperties.getMessage(resource, 
"loginservices.password_reminder_subject", UtilMisc.toMap("userLoginId", 
userLoginId), UtilHttp.getLocale(request)));
-            serviceContext.put("sendFrom", 
UtilProperties.getPropertyValue("general.properties", 
"defaultFromEmailAddress"));
+            GenericValue emailTemplateSetting = null;
+            try {
+                emailTemplateSetting = 
delegator.findOne("EmailTemplateSetting", true, "emailTemplateSettingId", 
"EMAIL_PASSWORD");
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+            }
+            if (emailTemplateSetting != null) {
+                String subject = emailTemplateSetting.getString("subject");
+                subject = FlexibleStringExpander.expandString(subject, 
UtilMisc.toMap("userLoginId", userLoginId));
+                serviceContext.put("subject", subject);                
+                serviceContext.put("sendFrom", 
emailTemplateSetting.get("fromAddress"));
+            } else {
+                serviceContext.put("subject", 
UtilProperties.getMessage(resource, "loginservices.password_reminder_subject", 
UtilMisc.toMap("userLoginId", userLoginId), UtilHttp.getLocale(request)));
+                serviceContext.put("sendFrom", 
EntityUtilProperties.getPropertyValue("general.properties", 
"defaultFromEmailAddress", delegator));
+            }            
         }
         serviceContext.put("sendTo", emails.toString());
         serviceContext.put("partyId", party.getString("partyId"));

Modified: ofbiz/trunk/framework/common/config/SecurityextUiLabels.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/SecurityextUiLabels.xml?rev=1310716&r1=1310715&r2=1310716&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/config/SecurityextUiLabels.xml (original)
+++ ofbiz/trunk/framework/common/config/SecurityextUiLabels.xml Sat Apr  7 
09:17:41 2012
@@ -699,7 +699,7 @@
     </property>
     <property key="loginservices.password_reminder_subject">
         <value xml:lang="en">Password Reminder (${userLoginId})".</value>
-        <value xml:lang="fr">Rappel du mot de passe(${userLoginId})".</value>
+        <value xml:lang="fr">Rappel du mot de passe (${userLoginId})".</value>
     </property>
     <property key="loginservices.since_datetime">
         <value xml:lang="de">(seit ${disabledDateTime})</value>


Reply via email to