mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Merge 1.x => dev
--HG-- branch : dev
This commit is contained in:
@@ -152,6 +152,39 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
||||
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]
|
||||
public void RegisteredUserShouldBeRedirectedToHomePage() {
|
||||
|
||||
|
@@ -110,7 +110,7 @@ namespace Orchard.Modules.Controllers {
|
||||
try {
|
||||
_reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
|
||||
_dataMigrationManager.Update(id);
|
||||
Services.Notifier.Information(T("The feature {0} was updated succesfuly", id));
|
||||
Services.Notifier.Information(T("The feature {0} was updated successfully", id));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, ex.Message));
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Orchard.Localization;
|
||||
using System.Security.Principal;
|
||||
@@ -317,6 +318,8 @@ 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;
|
||||
@@ -326,6 +329,11 @@ namespace Orchard.Users.Controllers {
|
||||
validate = false;
|
||||
}
|
||||
|
||||
if (!isValidEmail.IsMatch(email)) {
|
||||
ModelState.AddModelError("email", T("You must specify a valid email address."));
|
||||
validate = false;
|
||||
}
|
||||
|
||||
if (!validate)
|
||||
return false;
|
||||
|
||||
|
@@ -7,6 +7,7 @@ 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,6 +11,7 @@ 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; }
|
||||
|
29
src/Orchard/Mvc/Extensions/RouteExtension.cs
Normal file
29
src/Orchard/Mvc/Extensions/RouteExtension.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Web.Routing;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.Mvc.Extensions {
|
||||
public static class RouteExtension{
|
||||
public static string GetAreaName(this RouteBase route){
|
||||
var routeWithArea = route as IRouteWithArea;
|
||||
if (routeWithArea != null) {
|
||||
return routeWithArea.Area;
|
||||
}
|
||||
|
||||
var castRoute = route as Route;
|
||||
if (castRoute != null && castRoute.DataTokens != null) {
|
||||
return castRoute.DataTokens["area"] as string;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetAreaName(this RouteData routeData){
|
||||
object area;
|
||||
if (routeData.DataTokens.TryGetValue("area", out area)) {
|
||||
return area as string;
|
||||
}
|
||||
|
||||
return GetAreaName(routeData.Route);
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ using System.Web.Routing;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using Autofac.Features.Metadata;
|
||||
using Orchard.Mvc.Extensions;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public interface IControllerType {
|
||||
@@ -30,7 +31,7 @@ namespace Orchard.Mvc {
|
||||
var routeData = requestContext.RouteData;
|
||||
|
||||
// Determine the area name for the request, and fall back to stock orchard controllers
|
||||
var areaName = GetAreaName(routeData);
|
||||
var areaName = routeData.GetAreaName();
|
||||
|
||||
// Service name pattern matches the identification strategy
|
||||
var serviceKey = (areaName + "/" + controllerName).ToLowerInvariant();
|
||||
@@ -57,27 +58,5 @@ namespace Orchard.Mvc {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetAreaName(RouteBase route) {
|
||||
var routeWithArea = route as IRouteWithArea;
|
||||
if (routeWithArea != null) {
|
||||
return routeWithArea.Area;
|
||||
}
|
||||
|
||||
var castRoute = route as Route;
|
||||
if (castRoute != null && castRoute.DataTokens != null) {
|
||||
return castRoute.DataTokens["area"] as string;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetAreaName(RouteData routeData) {
|
||||
object area;
|
||||
if (routeData.DataTokens.TryGetValue("area", out area)) {
|
||||
return area as string;
|
||||
}
|
||||
|
||||
return GetAreaName(routeData.Route);
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ using System.Web.SessionState;
|
||||
using Autofac;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Mvc.Extensions;
|
||||
|
||||
namespace Orchard.Mvc.Routes {
|
||||
|
||||
@@ -25,15 +26,7 @@ namespace Orchard.Mvc.Routes {
|
||||
if (!string.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
|
||||
_urlPrefix = new UrlPrefix(_shellSettings.RequestUrlPrefix);
|
||||
|
||||
var routeWithArea = route as IRouteWithArea;
|
||||
if (routeWithArea != null) {
|
||||
Area = routeWithArea.Area;
|
||||
}
|
||||
|
||||
var routeWithDataTokens = route as Route;
|
||||
if ((routeWithDataTokens != null) && (routeWithDataTokens.DataTokens != null)) {
|
||||
Area = (routeWithDataTokens.DataTokens["area"] as string);
|
||||
}
|
||||
Area = route.GetAreaName();
|
||||
}
|
||||
|
||||
public string ShellSettingsName { get { return _shellSettings.Name; } }
|
||||
|
@@ -186,6 +186,7 @@
|
||||
<Compile Include="Localization\Services\ILocalizedStringManager.cs" />
|
||||
<Compile Include="Logging\OrchardFileAppender.cs" />
|
||||
<Compile Include="Messaging\Services\DefaultMessageManager.cs" />
|
||||
<Compile Include="Mvc\Extensions\RouteExtension.cs" />
|
||||
<Compile Include="Mvc\HttpContextWorkContext.cs" />
|
||||
<Compile Include="Mvc\Extensions\ControllerExtensions.cs" />
|
||||
<Compile Include="Mvc\IOrchardViewPage.cs" />
|
||||
|
Reference in New Issue
Block a user