From 3969aed2ad2d0e10a901491f9284bf88b70dbbf9 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 7 Jan 2011 17:02:52 -0800 Subject: [PATCH] Fixing email templating not to override unwanted messages --HG-- branch : 1.x --- .../Handlers/UserMessagesAlteration.cs | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Users/Handlers/UserMessagesAlteration.cs b/src/Orchard.Web/Modules/Orchard.Users/Handlers/UserMessagesAlteration.cs index 6a0ed0377..b66f2e133 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Handlers/UserMessagesAlteration.cs +++ b/src/Orchard.Web/Modules/Orchard.Users/Handlers/UserMessagesAlteration.cs @@ -31,30 +31,42 @@ namespace Orchard.Users.Handlers { if ( recipient == null ) return; - if ( context.Type == MessageTypes.Moderation ) { - context.MailMessage.Subject = T("New account").Text; - context.MailMessage.Body = T("The user {0} with email {1} has requested a new account. This user won't be able to log while his account has not been approved.", context.Properties["UserName"], context.Properties["Email"]).Text; + switch (context.Type) { + case MessageTypes.Moderation: + context.MailMessage.Subject = T("New account").Text; + context.MailMessage.Body = + T("The user {0} with email {1} has requested a new account. This user won't be able to log while his account has not been approved.", + context.Properties["UserName"], context.Properties["Email"]).Text; + FormatEmailBody(context); + context.MessagePrepared = true; + break; + + case MessageTypes.Validation: + var registeredWebsite = _siteService.GetSiteSettings().As().ValidateEmailRegisteredWebsite; + var contactEmail = _siteService.GetSiteSettings().As().ValidateEmailContactEMail; + context.MailMessage.Subject = T("Verification E-Mail").Text; + context.MailMessage.Body = + T("Thank you for registering with {0}.


Final Step
To verify that you own this e-mail address, please click the following link:
{1}

Troubleshooting:
If clicking on the link above does not work, try the following:

Select and copy the entire link.
Open a browser window and paste the link in the address bar.
Click Go or, on your keyboard, press Enter or Return.", + registeredWebsite, context.Properties["ChallengeUrl"]).Text; + + if (!String.IsNullOrWhiteSpace(contactEmail)) { + context.MailMessage.Body += + T("

If you continue to have access problems or want to report other issues, please Contact Us.", + contactEmail).Text; + } + FormatEmailBody(context); + context.MessagePrepared = true; + break; + + case MessageTypes.LostPassword: + context.MailMessage.Subject = T("Lost password").Text; + context.MailMessage.Body = + T("Dear {0}, please click here to change your password.", recipient.UserName, + context.Properties["LostPasswordUrl"]).Text; + FormatEmailBody(context); + context.MessagePrepared = true; + break; } - - if (context.Type == MessageTypes.Validation) { - var registeredWebsite = _siteService.GetSiteSettings().As().ValidateEmailRegisteredWebsite; - var contactEmail = _siteService.GetSiteSettings().As().ValidateEmailContactEMail; - context.MailMessage.Subject = T("Verification E-Mail").Text; - context.MailMessage.Body = - T("Thank you for registering with {0}.


Final Step
To verify that you own this e-mail address, please click the following link:
{1}

Troubleshooting:
If clicking on the link above does not work, try the following:

Select and copy the entire link.
Open a browser window and paste the link in the address bar.
Click Go or, on your keyboard, press Enter or Return.", registeredWebsite, context.Properties["ChallengeUrl"]).Text; - - if (!String.IsNullOrWhiteSpace(contactEmail)) { - context.MailMessage.Body += T("

If you continue to have access problems or want to report other issues, please Contact Us.", contactEmail).Text; - } - } - - if (context.Type == MessageTypes.LostPassword) { - context.MailMessage.Subject = T("Lost password").Text; - context.MailMessage.Body = T("Dear {0}, please click here to change your password.", recipient.UserName, context.Properties["LostPasswordUrl"]).Text; - } - - FormatEmailBody(context); - context.MessagePrepared = true; } private static void FormatEmailBody(MessageContext context) {