mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
@@ -22,6 +22,7 @@ namespace Orchard.Users.Controllers {
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
|
||||
public AccountController(
|
||||
IAuthenticationService authenticationService,
|
||||
@@ -320,18 +321,17 @@ namespace Orchard.Users.Controllers {
|
||||
private bool ValidateRegistration(string userName, string email, string password, string confirmPassword) {
|
||||
bool validate = true;
|
||||
|
||||
Regex isValidEmail = new Regex("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$");
|
||||
|
||||
if (String.IsNullOrEmpty(userName)) {
|
||||
ModelState.AddModelError("username", T("You must specify a username."));
|
||||
validate = false;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(email)) {
|
||||
ModelState.AddModelError("email", T("You must specify an email address."));
|
||||
validate = false;
|
||||
}
|
||||
|
||||
if (!isValidEmail.IsMatch(email)) {
|
||||
else if (!Regex.IsMatch(email, UserPart.EmailPattern, RegexOptions.IgnoreCase)) {
|
||||
// http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
|
||||
ModelState.AddModelError("email", T("You must specify a valid email address."));
|
||||
validate = false;
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -169,7 +170,12 @@ namespace Orchard.Users.Controllers {
|
||||
AddModelError("NotUniqueUserName", T("User with that username and/or email already exists."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!Regex.IsMatch(createModel.Email ?? "", UserPart.EmailPattern, RegexOptions.IgnoreCase)) {
|
||||
// http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
|
||||
ModelState.AddModelError("Email", T("You must specify a valid email address."));
|
||||
}
|
||||
|
||||
if (createModel.Password != createModel.ConfirmPassword) {
|
||||
AddModelError("ConfirmPassword", T("Password confirmation must match"));
|
||||
}
|
||||
@@ -229,6 +235,10 @@ namespace Orchard.Users.Controllers {
|
||||
if (!_userService.VerifyUserUnicity(id, editModel.UserName, editModel.Email)) {
|
||||
AddModelError("NotUniqueUserName", T("User with that username and/or email already exists."));
|
||||
}
|
||||
else if (!Regex.IsMatch(editModel.Email ?? "", UserPart.EmailPattern, RegexOptions.IgnoreCase)) {
|
||||
// http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
|
||||
ModelState.AddModelError("Email", T("You must specify a valid email address."));
|
||||
}
|
||||
else {
|
||||
// also update the Super user if this is the renamed account
|
||||
if (String.Equals(Services.WorkContext.CurrentSite.SuperUser, previousName, StringComparison.OrdinalIgnoreCase)) {
|
||||
|
@@ -3,6 +3,8 @@ using Orchard.Security;
|
||||
|
||||
namespace Orchard.Users.Models {
|
||||
public sealed class UserPart : ContentPart<UserPartRecord>, IUser {
|
||||
public const string EmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
|
||||
|
||||
public string UserName {
|
||||
get { return Record.UserName; }
|
||||
set { Record.UserName = value; }
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.ViewModels {
|
||||
public class UserCreateViewModel {
|
||||
@@ -7,7 +8,6 @@ namespace Orchard.Users.ViewModels {
|
||||
public string UserName { get; set; }
|
||||
|
||||
[Required, DataType(DataType.EmailAddress)]
|
||||
[RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required, DataType(DataType.Password)]
|
||||
|
@@ -11,7 +11,6 @@ namespace Orchard.Users.ViewModels {
|
||||
}
|
||||
|
||||
[Required]
|
||||
[RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$")]
|
||||
public string Email {
|
||||
get { return User.As<UserPart>().Record.Email; }
|
||||
set { User.As<UserPart>().Record.Email = value; }
|
||||
|
Reference in New Issue
Block a user