mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Backed out changeset: b7e1d65e4ea5
--HG-- branch : 1.x
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Moq;
|
using Moq;
|
||||||
@@ -124,18 +122,5 @@ namespace Orchard.Tests.Modules.Users.Services {
|
|||||||
Assert.That(username, Is.EqualTo("foo"));
|
Assert.That(username, Is.EqualTo("foo"));
|
||||||
Assert.That(validateByUtc, Is.GreaterThan(_clock.UtcNow));
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ namespace Orchard.Users.Controllers {
|
|||||||
_siteService.GetSiteSettings().As<SiteSettingsPart>().SuperUser = editModel.UserName;
|
_siteService.GetSiteSettings().As<SiteSettingsPart>().SuperUser = editModel.UserName;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.NormalizedUserName = editModel.UserName.ToUpperInvariant();
|
user.NormalizedUserName = editModel.UserName.ToLower();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,15 @@
|
|||||||
using System.Collections.Generic;
|
using Orchard.Data.Migration;
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.Data.Migration;
|
|
||||||
using Orchard.Users.Models;
|
|
||||||
|
|
||||||
namespace Orchard.Users {
|
namespace Orchard.Users {
|
||||||
public class UsersDataMigration : DataMigrationImpl {
|
public class UsersDataMigration : DataMigrationImpl {
|
||||||
|
|
||||||
public UsersDataMigration(IOrchardServices orchardServices) {
|
|
||||||
Services = orchardServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IOrchardServices Services { get; set; }
|
|
||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
SchemaBuilder.CreateTable("UserPartRecord",
|
SchemaBuilder.CreateTable("UserPartRecord",
|
||||||
table => table
|
table => table
|
||||||
.ContentPartRecord()
|
.ContentPartRecord()
|
||||||
.Column<string>("UserName")
|
.Column<string>("UserName")
|
||||||
.Column<string>("Email")
|
.Column<string>("Email")
|
||||||
.Column<string>("NormalizedUserName", c => c.Unique())
|
.Column<string>("NormalizedUserName")
|
||||||
.Column<string>("Password")
|
.Column<string>("Password")
|
||||||
.Column<string>("PasswordFormat")
|
.Column<string>("PasswordFormat")
|
||||||
.Column<string>("HashAlgorithm")
|
.Column<string>("HashAlgorithm")
|
||||||
@@ -41,17 +32,7 @@ namespace Orchard.Users {
|
|||||||
.Column<bool>("EnableLostPassword", c => c.WithDefault(false))
|
.Column<bool>("EnableLostPassword", c => c.WithDefault(false))
|
||||||
);
|
);
|
||||||
|
|
||||||
return 2;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
public int UpdateFrom1() {
|
|
||||||
IEnumerable<UserPart> users = Services.ContentManager.Query<UserPart, UserPartRecord>().List();
|
|
||||||
|
|
||||||
foreach (UserPart user in users) {
|
|
||||||
user.NormalizedUserName = user.UserName.ToUpperInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ namespace Orchard.Users.Services {
|
|||||||
|
|
||||||
user.Record.UserName = createUserParams.Username;
|
user.Record.UserName = createUserParams.Username;
|
||||||
user.Record.Email = createUserParams.Email;
|
user.Record.Email = createUserParams.Email;
|
||||||
user.Record.NormalizedUserName = createUserParams.Username.ToUpperInvariant();
|
user.Record.NormalizedUserName = createUserParams.Username.ToLower();
|
||||||
user.Record.HashAlgorithm = "SHA1";
|
user.Record.HashAlgorithm = "SHA1";
|
||||||
SetPassword(user.Record, createUserParams.Password);
|
SetPassword(user.Record, createUserParams.Password);
|
||||||
|
|
||||||
@@ -97,24 +97,18 @@ namespace Orchard.Users.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IUser GetUser(string username) {
|
public IUser GetUser(string username) {
|
||||||
var higherName = username == null ? "" : username.ToUpperInvariant();
|
var lowerName = username == null ? "" : username.ToLower();
|
||||||
|
|
||||||
return _orchardServices.ContentManager.Query<UserPart, UserPartRecord>()
|
return _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
|
||||||
.Where(u => u.NormalizedUserName == higherName).List()
|
|
||||||
.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.OrdinalIgnoreCase));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IUser ValidateUser(string userNameOrEmail, string password) {
|
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>()
|
var user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
|
||||||
.Where(u =>
|
|
||||||
u.NormalizedUserName == higherName ||
|
if (user == null)
|
||||||
u.Email == userNameOrEmail)
|
user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.Email == lowerName).List().FirstOrDefault();
|
||||||
.List()
|
|
||||||
.FirstOrDefault(u =>
|
|
||||||
u.UserName.Equals(userNameOrEmail, StringComparison.OrdinalIgnoreCase) ||
|
|
||||||
u.Email == userNameOrEmail);
|
|
||||||
|
|
||||||
if ( user == null || ValidatePassword(user.As<UserPart>().Record, password) == false )
|
if ( user == null || ValidatePassword(user.As<UserPart>().Record, password) == false )
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -37,16 +37,13 @@ namespace Orchard.Users.Services {
|
|||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
public bool VerifyUserUnicity(string userName, string email) {
|
public bool VerifyUserUnicity(string userName, string email) {
|
||||||
string normalizedUserName = userName.ToUpperInvariant();
|
string normalizedUserName = userName.ToLower();
|
||||||
|
|
||||||
if (_contentManager.Query<UserPart, UserPartRecord>()
|
if (_contentManager.Query<UserPart, UserPartRecord>()
|
||||||
.Where(user =>
|
.Where(user =>
|
||||||
user.NormalizedUserName == normalizedUserName ||
|
user.NormalizedUserName == normalizedUserName ||
|
||||||
user.Email == email)
|
user.Email == email)
|
||||||
.List()
|
.List().Any()) {
|
||||||
.Any(user =>
|
|
||||||
user.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) ||
|
|
||||||
user.Email == email)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,17 +51,13 @@ namespace Orchard.Users.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool VerifyUserUnicity(int id, string userName, string email) {
|
public bool VerifyUserUnicity(int id, string userName, string email) {
|
||||||
string normalizedUserName = userName.ToUpperInvariant();
|
string normalizedUserName = userName.ToLower();
|
||||||
|
|
||||||
if (_contentManager.Query<UserPart, UserPartRecord>()
|
if (_contentManager.Query<UserPart, UserPartRecord>()
|
||||||
.Where(user =>
|
.Where(user =>
|
||||||
user.NormalizedUserName == normalizedUserName ||
|
user.NormalizedUserName == normalizedUserName ||
|
||||||
user.Email == email)
|
user.Email == email)
|
||||||
.List()
|
.List().Any(user => user.Id != id)) {
|
||||||
.Any(user =>
|
|
||||||
(user.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) ||
|
|
||||||
user.Email == email) &&
|
|
||||||
user.Id != id)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user