mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Improving e-mail templates and settings for users registration
--HG-- branch : dev
This commit is contained in:
@@ -191,6 +191,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
|||||||
registrationSettings.UsersCanRegister = true;
|
registrationSettings.UsersCanRegister = true;
|
||||||
registrationSettings.UsersAreModerated = true;
|
registrationSettings.UsersAreModerated = true;
|
||||||
registrationSettings.NotifyModeration = true;
|
registrationSettings.NotifyModeration = true;
|
||||||
|
registrationSettings.NotificationsRecipients = "admin";
|
||||||
|
|
||||||
_container.Resolve<IWorkContextAccessor>().GetContext().CurrentSite.As<SiteSettingsPart>().SuperUser = "admin";
|
_container.Resolve<IWorkContextAccessor>().GetContext().CurrentSite.As<SiteSettingsPart>().SuperUser = "admin";
|
||||||
_session.Flush();
|
_session.Flush();
|
||||||
|
@@ -263,8 +263,8 @@ namespace Orchard.Users.Controllers {
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult ChallengeEmail(string token) {
|
public ActionResult ChallengeEmail(string nonce) {
|
||||||
var user = _userService.ValidateChallenge(token);
|
var user = _userService.ValidateChallenge(nonce);
|
||||||
|
|
||||||
if ( user != null ) {
|
if ( user != null ) {
|
||||||
_authenticationService.SignIn(user, false /* createPersistentCookie */);
|
_authenticationService.SignIn(user, false /* createPersistentCookie */);
|
||||||
|
@@ -1,15 +1,19 @@
|
|||||||
using Orchard.Localization;
|
using System;
|
||||||
|
using Orchard.Localization;
|
||||||
using Orchard.Messaging.Events;
|
using Orchard.Messaging.Events;
|
||||||
using Orchard.Messaging.Models;
|
using Orchard.Messaging.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Settings;
|
||||||
using Orchard.Users.Models;
|
using Orchard.Users.Models;
|
||||||
|
|
||||||
namespace Orchard.Users.Handlers {
|
namespace Orchard.Users.Handlers {
|
||||||
public class UserMessagesAlteration : IMessageEventHandler {
|
public class UserMessagesAlteration : IMessageEventHandler {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly ISiteService _siteService;
|
||||||
|
|
||||||
public UserMessagesAlteration(IContentManager contentManager) {
|
public UserMessagesAlteration(IContentManager contentManager, ISiteService siteService) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_siteService = siteService;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,8 +34,15 @@ namespace Orchard.Users.Handlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (context.Type == MessageTypes.Validation) {
|
if (context.Type == MessageTypes.Validation) {
|
||||||
context.MailMessage.Subject = T("User account validation").Text;
|
var registeredWebsite = _siteService.GetSiteSettings().As<RegistrationSettingsPart>().ValidateEmailRegisteredWebsite;
|
||||||
context.MailMessage.Body = T("Dear {0}, please <a href=\"{1}\">click here</a> to validate you email address.", recipient.UserName, context.Properties["ChallengeUrl"]).Text;
|
var contactEmail = _siteService.GetSiteSettings().As<RegistrationSettingsPart>().ValidateEmailContactEMail;
|
||||||
|
context.MailMessage.Subject = T("Verification E-Mail").Text;
|
||||||
|
context.MailMessage.Body =
|
||||||
|
T("Thank you for registering with {0}.<br/><br/><br/><b>Final Step</b><br/>To verify that you own this e-mail address, please click the following link:<br/><a href=\"{1}\">{1}</a><br/><br/><b>Troubleshooting:</b><br/>If clicking on the link above does not work, try the following:<br/><br/>Select and copy the entire link.<br/>Open a browser window and paste the link in the address bar.<br/>Click <b>Go</b> or, on your keyboard, press <b>Enter</b> or <b>Return</b>.", registeredWebsite, context.Properties["ChallengeUrl"]).Text;
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(contactEmail)) {
|
||||||
|
context.MailMessage.Body += T("<br/><br/>If you continue to have access problems or want to report other issues, please <a href=\"mailto:{0}\">Contact Us</a>.", contactEmail).Text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.Type == MessageTypes.LostPassword) {
|
if (context.Type == MessageTypes.LostPassword) {
|
||||||
@@ -39,6 +50,12 @@ namespace Orchard.Users.Handlers {
|
|||||||
context.MailMessage.Body = T("Dear {0}, please <a href=\"{1}\">click here</a> to change your password.", recipient.UserName, context.Properties["LostPasswordUrl"]).Text;
|
context.MailMessage.Body = T("Dear {0}, please <a href=\"{1}\">click here</a> to change your password.", recipient.UserName, context.Properties["LostPasswordUrl"]).Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FormatEmailBody(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FormatEmailBody(MessageContext context) {
|
||||||
|
context.MailMessage.Body = "<p style=\"font-family:Arial, Helvetica; font-size:10pt;\">" + context.MailMessage.Body;
|
||||||
|
context.MailMessage.Body += "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Sent(MessageContext context) {
|
public void Sent(MessageContext context) {
|
||||||
|
@@ -24,8 +24,11 @@ namespace Orchard.Users {
|
|||||||
.ContentPartRecord()
|
.ContentPartRecord()
|
||||||
.Column<bool>("UsersCanRegister", c => c.WithDefault(false))
|
.Column<bool>("UsersCanRegister", c => c.WithDefault(false))
|
||||||
.Column<bool>("UsersMustValidateEmail", c => c.WithDefault(false))
|
.Column<bool>("UsersMustValidateEmail", c => c.WithDefault(false))
|
||||||
|
.Column<string>("ValidateEmailRegisteredWebsite", c => c.WithLength(255))
|
||||||
|
.Column<string>("ValidateEmailContactEMail", c => c.WithLength(255))
|
||||||
.Column<bool>("UsersAreModerated", c => c.WithDefault(false))
|
.Column<bool>("UsersAreModerated", c => c.WithDefault(false))
|
||||||
.Column<bool>("NotifyModeration", c => c.WithDefault(false))
|
.Column<bool>("NotifyModeration", c => c.WithDefault(false))
|
||||||
|
.Column<string>("NotificationsRecipients", c => c.Unlimited())
|
||||||
.Column<bool>("EnableLostPassword", c => c.WithDefault(false))
|
.Column<bool>("EnableLostPassword", c => c.WithDefault(false))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -13,6 +13,16 @@ namespace Orchard.Users.Models {
|
|||||||
set { Record.UsersMustValidateEmail = value; }
|
set { Record.UsersMustValidateEmail = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ValidateEmailRegisteredWebsite {
|
||||||
|
get { return Record.ValidateEmailRegisteredWebsite; }
|
||||||
|
set { Record.ValidateEmailRegisteredWebsite = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ValidateEmailContactEMail {
|
||||||
|
get { return Record.ValidateEmailContactEMail; }
|
||||||
|
set { Record.ValidateEmailContactEMail = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public bool UsersAreModerated {
|
public bool UsersAreModerated {
|
||||||
get { return Record.UsersAreModerated; }
|
get { return Record.UsersAreModerated; }
|
||||||
set { Record.UsersAreModerated = value; }
|
set { Record.UsersAreModerated = value; }
|
||||||
@@ -23,6 +33,11 @@ namespace Orchard.Users.Models {
|
|||||||
set { Record.NotifyModeration = value; }
|
set { Record.NotifyModeration = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string NotificationsRecipients {
|
||||||
|
get { return Record.NotificationsRecipients; }
|
||||||
|
set { Record.NotificationsRecipients = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public bool EnableLostPassword {
|
public bool EnableLostPassword {
|
||||||
get { return Record.EnableLostPassword; }
|
get { return Record.EnableLostPassword; }
|
||||||
set { Record.EnableLostPassword = value; }
|
set { Record.EnableLostPassword = value; }
|
||||||
|
@@ -1,11 +1,19 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
|
|
||||||
namespace Orchard.Users.Models {
|
namespace Orchard.Users.Models {
|
||||||
public class RegistrationSettingsPartRecord : ContentPartRecord {
|
public class RegistrationSettingsPartRecord : ContentPartRecord {
|
||||||
public virtual bool UsersCanRegister { get; set; }
|
public virtual bool UsersCanRegister { get; set; }
|
||||||
public virtual bool UsersMustValidateEmail { get; set; }
|
public virtual bool UsersMustValidateEmail { get; set; }
|
||||||
|
[StringLength(255)]
|
||||||
|
public virtual string ValidateEmailRegisteredWebsite { get; set; }
|
||||||
|
[StringLength(255)]
|
||||||
|
public virtual string ValidateEmailContactEMail { get; set; }
|
||||||
|
|
||||||
public virtual bool UsersAreModerated { get; set; }
|
public virtual bool UsersAreModerated { get; set; }
|
||||||
public virtual bool NotifyModeration { get; set; }
|
public virtual bool NotifyModeration { get; set; }
|
||||||
|
public virtual string NotificationsRecipients { get; set; }
|
||||||
|
|
||||||
public virtual bool EnableLostPassword { get; set; }
|
public virtual bool EnableLostPassword { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -81,9 +81,18 @@ namespace Orchard.Users.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( registrationSettings != null && registrationSettings.UsersAreModerated && registrationSettings.NotifyModeration && !createUserParams.IsApproved ) {
|
if ( registrationSettings != null && registrationSettings.UsersAreModerated && registrationSettings.NotifyModeration && !createUserParams.IsApproved ) {
|
||||||
var superUser = GetUser(_orchardServices.WorkContext.CurrentSite.SuperUser);
|
var usernames = String.IsNullOrWhiteSpace(registrationSettings.NotificationsRecipients)
|
||||||
if(superUser != null)
|
? new string[0]
|
||||||
_messageManager.Send(superUser.ContentItem.Record, MessageTypes.Moderation, "email");
|
: registrationSettings.NotificationsRecipients.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach ( var userName in usernames ) {
|
||||||
|
if (String.IsNullOrWhiteSpace(userName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var recipient = GetUser(userName);
|
||||||
|
if (recipient != null)
|
||||||
|
_messageManager.Send(recipient.ContentItem.Record, MessageTypes.Moderation, "email");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@@ -22,11 +22,11 @@
|
|||||||
@foreach (var row in Model.Rows) {
|
@foreach (var row in Model.Rows) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@if(row.UserPart.RegistrationStatus == UserStatus.Approved) {
|
@if(row.UserPart.RegistrationStatus == UserStatus.Approved && row.UserPart.EmailStatus == UserStatus.Approved) {
|
||||||
<img class="icon" src="@Href("~/Modules/Orchard.Users/Content/Admin/images/online.gif") " alt="@T("Approved") " title="@T("User is approved") " />
|
<img class="icon" src="@Href("~/Modules/Orchard.Users/Content/Admin/images/online.gif") " alt="@T("Approved") " title="@T("User is approved") " />
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
<img class="icon" src="@Href("~/Modules/Orchard.Users/Content/Admin/images/offline.gif") " alt="@T("Moderated") " title="@T("User is moderated") " />
|
<img class="icon" src="@Href("~/Modules/Orchard.Users/Content/Admin/images/offline.gif") " alt="@T("Moderated") " title="@if(row.UserPart.EmailStatus == UserStatus.Approved) { @T("User is moderated") } else { @T("E-mail validation is pending") }" />
|
||||||
}
|
}
|
||||||
@Html.ActionLink(row.UserPart.UserName, "Edit", new { row.UserPart.Id })
|
@Html.ActionLink(row.UserPart.UserName, "Edit", new { row.UserPart.Id })
|
||||||
</td>
|
</td>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
@Html.ActionLink(T("Disable").ToString(), "Moderate", new { row.UserPart.Id })
|
@Html.ActionLink(T("Disable").ToString(), "Moderate", new { row.UserPart.Id })
|
||||||
}
|
}
|
||||||
@if ( row.UserPart.EmailStatus == UserStatus.Pending ) { <text>|</text>
|
@if ( row.UserPart.EmailStatus == UserStatus.Pending ) { <text>|</text>
|
||||||
@Html.ActionLink(T("Challenge Email").ToString(), "SendChallengeEmail", new { row.UserPart.Id })
|
@Html.ActionLink(T("Send challenge E-mail").ToString(), "SendChallengeEmail", new { row.UserPart.Id })
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -5,26 +5,38 @@
|
|||||||
<div>
|
<div>
|
||||||
@Html.EditorFor(m => m.UsersCanRegister)
|
@Html.EditorFor(m => m.UsersCanRegister)
|
||||||
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.UsersCanRegister)">@T("Users can create new accounts on the site")</label>
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.UsersCanRegister)">@T("Users can create new accounts on the site")</label>
|
||||||
@Html.ValidationMessage("UsersCanRegister", "*")
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@Html.EditorFor(m => m.EnableLostPassword)
|
@Html.EditorFor(m => m.EnableLostPassword)
|
||||||
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.EnableLostPassword)">@T("Display a link to enable users to reset their email")</label>
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.EnableLostPassword)">@T("Display a link to enable users to reset their email")</label>
|
||||||
@Html.ValidationMessage("EnableLostPassword", "*")
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@Html.EditorFor(m => m.UsersMustValidateEmail)
|
@Html.EditorFor(m => m.UsersMustValidateEmail)
|
||||||
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.UsersMustValidateEmail)">@T("Users must verify their email address")</label>
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.UsersMustValidateEmail)">@T("Users must verify their email address")</label>
|
||||||
@Html.ValidationMessage("UsersMustValidateEmail", "*")
|
</div>
|
||||||
|
<div data-controllerid="@Html.FieldIdFor(m => m.UsersMustValidateEmail)">
|
||||||
|
<label for="@Html.FieldIdFor( m => m.ValidateEmailRegisteredWebsite)">@T("Website public name")</label>
|
||||||
|
@Html.TextBoxFor(m => m.ValidateEmailRegisteredWebsite, new { @class = "textMedium" } )
|
||||||
|
@Html.ValidationMessage("ValidateEmailRegisteredWebsite", "*")
|
||||||
|
<span class="hint">@T("The name of your website as it will appear in the verification e-mail.")</span>
|
||||||
|
|
||||||
|
<label for="@Html.FieldIdFor( m => m.ValidateEmailContactEMail)">@T("Contact Us E-Mail address")</label>
|
||||||
|
@Html.TextBoxFor(m => m.ValidateEmailContactEMail, new { @class = "textMedium" } )
|
||||||
|
@Html.ValidationMessage("ValidateEmailContactEMail", "*")
|
||||||
|
<span class="hint">@T("The e-mail address displayed in the verification e-mail for a Contact Us link. Leave empty for no link.")</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@Html.EditorFor(m => m.UsersAreModerated)
|
@Html.EditorFor(m => m.UsersAreModerated)
|
||||||
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.UsersAreModerated)">@T("Users must be approved before they can log in")</label>
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.UsersAreModerated)">@T("Users must be approved before they can log in")</label>
|
||||||
@Html.ValidationMessage("UsersAreModerated", "*")
|
|
||||||
</div>
|
</div>
|
||||||
<div data-controllerid="@Html.FieldIdFor(m => m.UsersAreModerated)">
|
<div data-controllerid="@Html.FieldIdFor(m => m.UsersAreModerated)">
|
||||||
@Html.EditorFor(m => m.NotifyModeration)
|
@Html.EditorFor(m => m.NotifyModeration)
|
||||||
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.NotifyModeration)">@T("Send a notification when a user needs moderation")</label>
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.NotifyModeration)">@T("Send a notification when a user needs moderation")</label>
|
||||||
@Html.ValidationMessage("NotifyModeration", "*")
|
|
||||||
</div>
|
</div>
|
||||||
|
<div data-controllerid="@Html.FieldIdFor(m => m.NotifyModeration)">
|
||||||
|
<label for="@Html.FieldIdFor( m => m.NotificationsRecipients)">@T("Moderators")</label>
|
||||||
|
@Html.TextBoxFor(m => m.NotificationsRecipients, new { @class = "textMedium" } )
|
||||||
|
@Html.ValidationMessage("NotificationsRecipients", "*")
|
||||||
|
<span class="hint">@T("The usernames to send the notifications to (e.g., \"admin, user1, ...\").")</span>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
Reference in New Issue
Block a user