This commit is contained in:
Suha Can
2010-04-16 13:33:45 -07:00
parent 13783e748a
commit d4b79ea272

View File

@@ -1,6 +1,6 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using Orchard.Localization;
using System.Security.Principal; using System.Security.Principal;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Security; using System.Web.Security;
@@ -26,9 +26,11 @@ 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"];
@@ -98,7 +100,7 @@ namespace Orchard.Users.Controllers {
return Redirect("~/"); return Redirect("~/");
} }
else { else {
ModelState.AddModelError("_FORM", ErrorCodeToString(/*createStatus*/MembershipCreateStatus.ProviderError)); ModelState.AddModelError("_FORM", T(ErrorCodeToString(/*createStatus*/MembershipCreateStatus.ProviderError)));
} }
} }
@@ -133,12 +135,12 @@ namespace Orchard.Users.Controllers {
} }
else { else {
ModelState.AddModelError("_FORM", ModelState.AddModelError("_FORM",
"The current password is incorrect or the new password is invalid."); T("The current password is incorrect or the new password is invalid."));
return ChangePassword(); return ChangePassword();
} }
} }
catch { catch {
ModelState.AddModelError("_FORM", "The current password is incorrect or the new password is invalid."); ModelState.AddModelError("_FORM", T("The current password is incorrect or the new password is invalid."));
return ChangePassword(); return ChangePassword();
} }
} }
@@ -157,17 +159,14 @@ 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", "You must specify a current password."); ModelState.AddModelError("currentPassword", T("You must specify a current password."));
} }
if (newPassword == null || newPassword.Length < MinPasswordLength) { if (newPassword == null || newPassword.Length < MinPasswordLength) {
ModelState.AddModelError("newPassword", ModelState.AddModelError("newPassword", T("You must specify a new password of {0} or more characters.", MinPasswordLength));
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", "The new password and confirmation password do not match."); ModelState.AddModelError("_FORM", T("The new password and confirmation password do not match."));
} }
return ModelState.IsValid; return ModelState.IsValid;
@@ -175,14 +174,14 @@ namespace Orchard.Users.Controllers {
private IUser ValidateLogOn(string userNameOrEmail, string password) { private IUser ValidateLogOn(string userNameOrEmail, string password) {
if (String.IsNullOrEmpty(userNameOrEmail)) { if (String.IsNullOrEmpty(userNameOrEmail)) {
ModelState.AddModelError("userNameOrEmail", "You must specify a username or e-mail."); ModelState.AddModelError("userNameOrEmail", T("You must specify a username or e-mail."));
} }
if (String.IsNullOrEmpty(password)) { if (String.IsNullOrEmpty(password)) {
ModelState.AddModelError("password", "You must specify a password."); ModelState.AddModelError("password", T("You must specify a password."));
} }
var user = _membershipService.ValidateUser(userNameOrEmail, password); var user = _membershipService.ValidateUser(userNameOrEmail, password);
if (user == null) { if (user == null) {
ModelState.AddModelError("_FORM", "The username or e-mail or password provided is incorrect."); ModelState.AddModelError("_FORM", T("The username or e-mail or password provided is incorrect."));
} }
return user; return user;
@@ -190,23 +189,20 @@ 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", "You must specify a username."); ModelState.AddModelError("username", T("You must specify a username."));
} }
if (String.IsNullOrEmpty(email)) { if (String.IsNullOrEmpty(email)) {
ModelState.AddModelError("email", "You must specify an email address."); ModelState.AddModelError("email", T("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", userUnicityMessage); ModelState.AddModelError("userExists", T(userUnicityMessage));
} }
if (password == null || password.Length < MinPasswordLength) { if (password == null || password.Length < MinPasswordLength) {
ModelState.AddModelError("password", ModelState.AddModelError("password", T("You must specify a password of {0} or more characters.", MinPasswordLength));
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", "The new password and confirmation password do not match."); ModelState.AddModelError("_FORM", T("The new password and confirmation password do not match."));
} }
return ModelState.IsValid; return ModelState.IsValid;
} }