--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-04-07 16:07:20 -07:00
5 changed files with 16 additions and 63 deletions

View File

@@ -1,6 +1,4 @@
using System;
using System.Globalization;
using System.Threading;
using System.Xml.Linq;
using Autofac;
using Moq;
@@ -124,18 +122,5 @@ namespace Orchard.Tests.Modules.Users.Services {
Assert.That(username, Is.EqualTo("foo"));
Assert.That(validateByUtc, Is.GreaterThan(_clock.UtcNow));
}
[Test]
public void VerifyUserUnicityTurkishTest() {
CultureInfo turkishCulture = new CultureInfo("tr-TR");
Thread.CurrentThread.CurrentCulture = turkishCulture;
// Create user lower case
_membershipService.CreateUser(new CreateUserParams("admin", "66554321", "foo@bar.com", "", "", true));
_container.Resolve<IOrchardServices>().ContentManager.Flush();
// Verify unicity with upper case which with turkish coallition would yeld admin with an i without the dot and therefore generate a different user name
Assert.That(_userService.VerifyUserUnicity("ADMIN", "differentfoo@bar.com"), Is.False); // should fail
}
}
}

View File

@@ -245,7 +245,7 @@ namespace Orchard.Users.Controllers {
_siteService.GetSiteSettings().As<SiteSettingsPart>().SuperUser = editModel.UserName;
}
user.NormalizedUserName = editModel.UserName.ToUpperInvariant();
user.NormalizedUserName = editModel.UserName.ToLower();
}
}

View File

@@ -1,24 +1,15 @@
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.Data.Migration;
using Orchard.Users.Models;
using Orchard.Data.Migration;
namespace Orchard.Users {
public class UsersDataMigration : DataMigrationImpl {
public UsersDataMigration(IOrchardServices orchardServices) {
Services = orchardServices;
}
public IOrchardServices Services { get; set; }
public int Create() {
SchemaBuilder.CreateTable("UserPartRecord",
table => table
.ContentPartRecord()
.Column<string>("UserName")
.Column<string>("Email")
.Column<string>("NormalizedUserName", c => c.Unique())
.Column<string>("NormalizedUserName")
.Column<string>("Password")
.Column<string>("PasswordFormat")
.Column<string>("HashAlgorithm")
@@ -41,17 +32,7 @@ namespace Orchard.Users {
.Column<bool>("EnableLostPassword", c => c.WithDefault(false))
);
return 2;
}
public int UpdateFrom1() {
IEnumerable<UserPart> users = Services.ContentManager.Query<UserPart, UserPartRecord>().List();
foreach (UserPart user in users) {
user.NormalizedUserName = user.UserName.ToUpperInvariant();
}
return 2;
return 1;
}
}
}

View File

@@ -49,7 +49,7 @@ namespace Orchard.Users.Services {
user.Record.UserName = createUserParams.Username;
user.Record.Email = createUserParams.Email;
user.Record.NormalizedUserName = createUserParams.Username.ToUpperInvariant();
user.Record.NormalizedUserName = createUserParams.Username.ToLower();
user.Record.HashAlgorithm = "SHA1";
SetPassword(user.Record, createUserParams.Password);
@@ -97,24 +97,18 @@ namespace Orchard.Users.Services {
}
public IUser GetUser(string username) {
var higherName = username == null ? "" : username.ToUpperInvariant();
var lowerName = username == null ? "" : username.ToLower();
return _orchardServices.ContentManager.Query<UserPart, UserPartRecord>()
.Where(u => u.NormalizedUserName == higherName).List()
.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.OrdinalIgnoreCase));
return _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
}
public IUser ValidateUser(string userNameOrEmail, string password) {
var higherName = userNameOrEmail == null ? "" : userNameOrEmail.ToUpperInvariant();
var lowerName = userNameOrEmail == null ? "" : userNameOrEmail.ToLower();
var user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>()
.Where(u =>
u.NormalizedUserName == higherName ||
u.Email == userNameOrEmail)
.List()
.FirstOrDefault(u =>
u.UserName.Equals(userNameOrEmail, StringComparison.OrdinalIgnoreCase) ||
u.Email == userNameOrEmail);
var user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
if (user == null)
user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.Email == lowerName).List().FirstOrDefault();
if ( user == null || ValidatePassword(user.As<UserPart>().Record, password) == false )
return null;

View File

@@ -37,16 +37,13 @@ namespace Orchard.Users.Services {
public ILogger Logger { get; set; }
public bool VerifyUserUnicity(string userName, string email) {
string normalizedUserName = userName.ToUpperInvariant();
string normalizedUserName = userName.ToLower();
if (_contentManager.Query<UserPart, UserPartRecord>()
.Where(user =>
user.NormalizedUserName == normalizedUserName ||
user.Email == email)
.List()
.Any(user =>
user.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) ||
user.Email == email)) {
.List().Any()) {
return false;
}
@@ -54,17 +51,13 @@ namespace Orchard.Users.Services {
}
public bool VerifyUserUnicity(int id, string userName, string email) {
string normalizedUserName = userName.ToUpperInvariant();
string normalizedUserName = userName.ToLower();
if (_contentManager.Query<UserPart, UserPartRecord>()
.Where(user =>
user.NormalizedUserName == normalizedUserName ||
user.Email == email)
.List()
.Any(user =>
(user.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) ||
user.Email == email) &&
user.Id != id)) {
.List().Any(user => user.Id != id)) {
return false;
}