mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Merge
--HG-- branch : 1.x
This commit is contained in:
@@ -152,6 +152,41 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
|||||||
Assert.That(result, Is.TypeOf<ViewResult>());
|
Assert.That(result, Is.TypeOf<ViewResult>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UsersShouldNotBeAbleToRegisterIfInvalidEmail()
|
||||||
|
{
|
||||||
|
|
||||||
|
var registrationSettings = _container.Resolve<IWorkContextAccessor>().GetContext().CurrentSite.As<RegistrationSettingsPart>();
|
||||||
|
registrationSettings.UsersCanRegister = true;
|
||||||
|
registrationSettings.UsersAreModerated = false;
|
||||||
|
registrationSettings.UsersMustValidateEmail = false;
|
||||||
|
|
||||||
|
_session.Flush();
|
||||||
|
|
||||||
|
_controller.ModelState.Clear();
|
||||||
|
var result = _controller.Register("bar", "notanemailaddress", "66554321", "66554321");
|
||||||
|
|
||||||
|
Assert.That(((ViewResult)result).ViewData.ModelState.Count == 1,"Invalid email address.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UsersShouldBeAbleToRegisterIfValidEmail()
|
||||||
|
{
|
||||||
|
|
||||||
|
var registrationSettings = _container.Resolve<IWorkContextAccessor>().GetContext().CurrentSite.As<RegistrationSettingsPart>();
|
||||||
|
registrationSettings.UsersCanRegister = true;
|
||||||
|
registrationSettings.UsersAreModerated = false;
|
||||||
|
registrationSettings.UsersMustValidateEmail = false;
|
||||||
|
|
||||||
|
_session.Flush();
|
||||||
|
|
||||||
|
_controller.ModelState.Clear();
|
||||||
|
var result = _controller.Register("bar", "t@t.com", "password", "password");
|
||||||
|
|
||||||
|
Assert.That(result, Is.TypeOf<RedirectResult>());
|
||||||
|
Assert.That(((RedirectResult)result).Url, Is.EqualTo("~/"));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void RegisteredUserShouldBeRedirectedToHomePage() {
|
public void RegisteredUserShouldBeRedirectedToHomePage() {
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
@@ -317,6 +318,8 @@ namespace Orchard.Users.Controllers {
|
|||||||
private bool ValidateRegistration(string userName, string email, string password, string confirmPassword) {
|
private bool ValidateRegistration(string userName, string email, string password, string confirmPassword) {
|
||||||
bool validate = true;
|
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)) {
|
if (String.IsNullOrEmpty(userName)) {
|
||||||
ModelState.AddModelError("username", T("You must specify a username."));
|
ModelState.AddModelError("username", T("You must specify a username."));
|
||||||
validate = false;
|
validate = false;
|
||||||
@@ -326,6 +329,11 @@ namespace Orchard.Users.Controllers {
|
|||||||
validate = false;
|
validate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isValidEmail.IsMatch(email)) {
|
||||||
|
ModelState.AddModelError("email", T("You must specify a valid email address."));
|
||||||
|
validate = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!validate)
|
if (!validate)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ namespace Orchard.Users.ViewModels {
|
|||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
|
||||||
[Required, DataType(DataType.EmailAddress)]
|
[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; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
[Required, DataType(DataType.Password)]
|
[Required, DataType(DataType.Password)]
|
||||||
|
@@ -11,6 +11,7 @@ namespace Orchard.Users.ViewModels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
|
[RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$")]
|
||||||
public string Email {
|
public string Email {
|
||||||
get { return User.As<UserPart>().Record.Email; }
|
get { return User.As<UserPart>().Record.Email; }
|
||||||
set { User.As<UserPart>().Record.Email = value; }
|
set { User.As<UserPart>().Record.Email = value; }
|
||||||
|
Reference in New Issue
Block a user