mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
- Patch for issue #16396 by Andrew Ma
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Globalization;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Security;
|
using System.Web.Security;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Mvc.Extensions;
|
using Orchard.Mvc.Extensions;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
@@ -26,11 +26,9 @@ namespace Orchard.Users.Controllers {
|
|||||||
_membershipService = membershipService;
|
_membershipService = membershipService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
public Localizer T { get; set; }
|
|
||||||
|
|
||||||
public ActionResult AccessDenied() {
|
public ActionResult AccessDenied() {
|
||||||
var returnUrl = Request.QueryString["ReturnUrl"];
|
var returnUrl = Request.QueryString["ReturnUrl"];
|
||||||
@@ -57,8 +55,8 @@ namespace Orchard.Users.Controllers {
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
|
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
|
||||||
Justification = "Needs to take same parameter type as Controller.Redirect()")]
|
Justification = "Needs to take same parameter type as Controller.Redirect()")]
|
||||||
public ActionResult LogOn(string userName, string password, bool rememberMe) {
|
public ActionResult LogOn(string userNameOrEmail, string password, bool rememberMe) {
|
||||||
var user = ValidateLogOn(userName, password);
|
var user = ValidateLogOn(userNameOrEmail, password);
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
return View("LogOn", new LogOnViewModel {Title = "Log On"});
|
return View("LogOn", new LogOnViewModel {Title = "Log On"});
|
||||||
}
|
}
|
||||||
@@ -100,7 +98,7 @@ namespace Orchard.Users.Controllers {
|
|||||||
return Redirect("~/");
|
return Redirect("~/");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ModelState.AddModelError("_FORM", T(ErrorCodeToString(/*createStatus*/MembershipCreateStatus.ProviderError)));
|
ModelState.AddModelError("_FORM", ErrorCodeToString(/*createStatus*/MembershipCreateStatus.ProviderError));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,12 +132,13 @@ namespace Orchard.Users.Controllers {
|
|||||||
return RedirectToAction("ChangePasswordSuccess");
|
return RedirectToAction("ChangePasswordSuccess");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ModelState.AddModelError("_FORM", T("The current password is incorrect or the new password is invalid."));
|
ModelState.AddModelError("_FORM",
|
||||||
|
"The current password is incorrect or the new password is invalid.");
|
||||||
return ChangePassword();
|
return ChangePassword();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
ModelState.AddModelError("_FORM", T("The current password is incorrect or the new password is invalid."));
|
ModelState.AddModelError("_FORM", "The current password is incorrect or the new password is invalid.");
|
||||||
return ChangePassword();
|
return ChangePassword();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,29 +157,32 @@ namespace Orchard.Users.Controllers {
|
|||||||
|
|
||||||
private bool ValidateChangePassword(string currentPassword, string newPassword, string confirmPassword) {
|
private bool ValidateChangePassword(string currentPassword, string newPassword, string confirmPassword) {
|
||||||
if (String.IsNullOrEmpty(currentPassword)) {
|
if (String.IsNullOrEmpty(currentPassword)) {
|
||||||
ModelState.AddModelError("currentPassword", T("You must specify a current password."));
|
ModelState.AddModelError("currentPassword", "You must specify a current password.");
|
||||||
}
|
}
|
||||||
if (newPassword == null || newPassword.Length < MinPasswordLength) {
|
if (newPassword == null || newPassword.Length < MinPasswordLength) {
|
||||||
ModelState.AddModelError("newPassword", T("You must specify a new password of {0} or more characters.", MinPasswordLength));
|
ModelState.AddModelError("newPassword",
|
||||||
|
String.Format(CultureInfo.CurrentCulture,
|
||||||
|
"You must specify a new password of {0} or more characters.",
|
||||||
|
MinPasswordLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!String.Equals(newPassword, confirmPassword, StringComparison.Ordinal)) {
|
if (!String.Equals(newPassword, confirmPassword, StringComparison.Ordinal)) {
|
||||||
ModelState.AddModelError("_FORM", T("The new password and confirmation password do not match."));
|
ModelState.AddModelError("_FORM", "The new password and confirmation password do not match.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ModelState.IsValid;
|
return ModelState.IsValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IUser ValidateLogOn(string userName, string password) {
|
private IUser ValidateLogOn(string userNameOrEmail, string password) {
|
||||||
if (String.IsNullOrEmpty(userName)) {
|
if (String.IsNullOrEmpty(userNameOrEmail)) {
|
||||||
ModelState.AddModelError("username", T("You must specify a username."));
|
ModelState.AddModelError("userNameOrEmail", "You must specify a username or e-mail.");
|
||||||
}
|
}
|
||||||
if (String.IsNullOrEmpty(password)) {
|
if (String.IsNullOrEmpty(password)) {
|
||||||
ModelState.AddModelError("password", T("You must specify a password."));
|
ModelState.AddModelError("password", "You must specify a password.");
|
||||||
}
|
}
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userNameOrEmail, password);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ModelState.AddModelError("_FORM", T("The username or password provided is incorrect."));
|
ModelState.AddModelError("_FORM", "The username or e-mail or password provided is incorrect.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
@@ -188,20 +190,23 @@ 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) {
|
||||||
if (String.IsNullOrEmpty(userName)) {
|
if (String.IsNullOrEmpty(userName)) {
|
||||||
ModelState.AddModelError("username", T("You must specify a username."));
|
ModelState.AddModelError("username", "You must specify a username.");
|
||||||
}
|
}
|
||||||
if (String.IsNullOrEmpty(email)) {
|
if (String.IsNullOrEmpty(email)) {
|
||||||
ModelState.AddModelError("email", T("You must specify an email address."));
|
ModelState.AddModelError("email", "You must specify an email address.");
|
||||||
}
|
}
|
||||||
string userUnicityMessage = _userService.VerifyUserUnicity(userName, email);
|
string userUnicityMessage = _userService.VerifyUserUnicity(userName, email);
|
||||||
if (userUnicityMessage != null) {
|
if (userUnicityMessage != null) {
|
||||||
ModelState.AddModelError("userExists", T(userUnicityMessage));
|
ModelState.AddModelError("userExists", userUnicityMessage);
|
||||||
}
|
}
|
||||||
if (password == null || password.Length < MinPasswordLength) {
|
if (password == null || password.Length < MinPasswordLength) {
|
||||||
ModelState.AddModelError("password", T("You must specify a password of {0} or more characters.", MinPasswordLength));
|
ModelState.AddModelError("password",
|
||||||
|
String.Format(CultureInfo.CurrentCulture,
|
||||||
|
"You must specify a password of {0} or more characters.",
|
||||||
|
MinPasswordLength));
|
||||||
}
|
}
|
||||||
if (!String.Equals(password, confirmPassword, StringComparison.Ordinal)) {
|
if (!String.Equals(password, confirmPassword, StringComparison.Ordinal)) {
|
||||||
ModelState.AddModelError("_FORM", T("The new password and confirmation password do not match."));
|
ModelState.AddModelError("_FORM", "The new password and confirmation password do not match.");
|
||||||
}
|
}
|
||||||
return ModelState.IsValid;
|
return ModelState.IsValid;
|
||||||
}
|
}
|
||||||
|
@@ -51,8 +51,10 @@ namespace Orchard.Users.Services {
|
|||||||
return _contentManager.Get<IUser>(userRecord.Id);
|
return _contentManager.Get<IUser>(userRecord.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IUser ValidateUser(string username, string password) {
|
public IUser ValidateUser(string userNameOrEmail, string password) {
|
||||||
var userRecord = _userRepository.Get(x => x.NormalizedUserName == username.ToLower());
|
var userRecord = _userRepository.Get(x => x.NormalizedUserName == userNameOrEmail.ToLower());
|
||||||
|
if(userRecord == null)
|
||||||
|
userRecord = _userRepository.Get(x => x.Email == userNameOrEmail.ToLower());
|
||||||
if (userRecord == null || ValidatePassword(userRecord, password) == false)
|
if (userRecord == null || ValidatePassword(userRecord, password) == false)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@@ -8,9 +8,9 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%=_Encoded("Account Information")%></legend>
|
<legend><%=_Encoded("Account Information")%></legend>
|
||||||
<div>
|
<div>
|
||||||
<label for="username"><%=_Encoded("Username:")%></label>
|
<label for="username"><%=_Encoded("Username or Email:")%></label>
|
||||||
<%= Html.TextBox("username")%>
|
<%= Html.TextBox("userNameOrEmail")%>
|
||||||
<%= Html.ValidationMessage("username")%>
|
<%= Html.ValidationMessage("userNameOrEmail")%>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="password"><%=_Encoded("Password:")%></label>
|
<label for="password"><%=_Encoded("Password:")%></label>
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
IUser CreateUser(CreateUserParams createUserParams);
|
IUser CreateUser(CreateUserParams createUserParams);
|
||||||
IUser GetUser(string username);
|
IUser GetUser(string username);
|
||||||
|
|
||||||
IUser ValidateUser(string username, string password);
|
IUser ValidateUser(string userNameOrEmail, string password);
|
||||||
void SetPassword(IUser user, string password);
|
void SetPassword(IUser user, string password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user