mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
User -> UserPart
- updating part names to conform to a <name>Part convention --HG-- branch : dev rename : src/Orchard.Web/Modules/Orchard.Users/Drivers/UserDriver.cs => src/Orchard.Web/Modules/Orchard.Users/Drivers/UserPartDriver.cs rename : src/Orchard.Web/Modules/Orchard.Users/Handlers/UserHandler.cs => src/Orchard.Web/Modules/Orchard.Users/Handlers/UserPartHandler.cs rename : src/Orchard.Web/Modules/Orchard.Users/Models/User.cs => src/Orchard.Web/Modules/Orchard.Users/Models/UserPart.cs rename : src/Orchard.Web/Modules/Orchard.Users/Models/UserRecord.cs => src/Orchard.Web/Modules/Orchard.Users/Models/UserPartRecord.cs
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
|||||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>().InstancePerDependency();
|
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>().InstancePerDependency();
|
||||||
builder.RegisterType<MembershipService>().As<IMembershipService>();
|
builder.RegisterType<MembershipService>().As<IMembershipService>();
|
||||||
builder.RegisterType<UserService>().As<IUserService>();
|
builder.RegisterType<UserService>().As<IUserService>();
|
||||||
builder.RegisterType<UserHandler>().As<IContentHandler>();
|
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||||
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
|
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
|
||||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||||
@@ -53,7 +53,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
|||||||
|
|
||||||
protected override IEnumerable<Type> DatabaseTypes {
|
protected override IEnumerable<Type> DatabaseTypes {
|
||||||
get {
|
get {
|
||||||
return new[] { typeof(UserRecord),
|
return new[] { typeof(UserPartRecord),
|
||||||
typeof(ContentTypeRecord),
|
typeof(ContentTypeRecord),
|
||||||
typeof(ContentItemRecord),
|
typeof(ContentItemRecord),
|
||||||
typeof(ContentItemVersionRecord),
|
typeof(ContentItemVersionRecord),
|
||||||
@@ -66,16 +66,16 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
|||||||
|
|
||||||
var manager = _container.Resolve<IContentManager>();
|
var manager = _container.Resolve<IContentManager>();
|
||||||
|
|
||||||
var userOne = manager.New<User>("User");
|
var userOne = manager.New<UserPart>("User");
|
||||||
userOne.Record = new UserRecord { UserName = "one" };
|
userOne.Record = new UserPartRecord { UserName = "one" };
|
||||||
manager.Create(userOne.ContentItem);
|
manager.Create(userOne.ContentItem);
|
||||||
|
|
||||||
var userTwo = manager.New<User>("User");
|
var userTwo = manager.New<UserPart>("User");
|
||||||
userTwo.Record = new UserRecord { UserName = "two" };
|
userTwo.Record = new UserPartRecord { UserName = "two" };
|
||||||
manager.Create(userTwo.ContentItem);
|
manager.Create(userTwo.ContentItem);
|
||||||
|
|
||||||
var userThree = manager.New<User>("User");
|
var userThree = manager.New<UserPart>("User");
|
||||||
userThree.Record = new UserRecord { UserName = "three" };
|
userThree.Record = new UserPartRecord { UserName = "three" };
|
||||||
manager.Create(userThree.ContentItem);
|
manager.Create(userThree.ContentItem);
|
||||||
|
|
||||||
_controller = _container.Resolve<AdminController>();
|
_controller = _container.Resolve<AdminController>();
|
||||||
@@ -125,7 +125,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
|||||||
public void EditShouldDisplayUserAndStoreChanges() {
|
public void EditShouldDisplayUserAndStoreChanges() {
|
||||||
_authorizer.Setup(x => x.Authorize(It.IsAny<Permission>(), It.IsAny<LocalizedString>())).Returns(true);
|
_authorizer.Setup(x => x.Authorize(It.IsAny<Permission>(), It.IsAny<LocalizedString>())).Returns(true);
|
||||||
|
|
||||||
var repository = _container.Resolve<IRepository<UserRecord>>();
|
var repository = _container.Resolve<IRepository<UserPartRecord>>();
|
||||||
var id = repository.Get(x => x.UserName == "two").Id;
|
var id = repository.Get(x => x.UserName == "two").Id;
|
||||||
var result = (ViewResult)_container.Resolve<AdminController>().Edit(id);
|
var result = (ViewResult)_container.Resolve<AdminController>().Edit(id);
|
||||||
var model = (UserEditViewModel)result.ViewData.Model;
|
var model = (UserEditViewModel)result.ViewData.Model;
|
||||||
|
@@ -43,7 +43,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
|||||||
var databaseFileName = System.IO.Path.GetTempFileName();
|
var databaseFileName = System.IO.Path.GetTempFileName();
|
||||||
_sessionFactory = DataUtility.CreateSessionFactory(
|
_sessionFactory = DataUtility.CreateSessionFactory(
|
||||||
databaseFileName,
|
databaseFileName,
|
||||||
typeof(UserRecord),
|
typeof(UserPartRecord),
|
||||||
typeof(ContentItemVersionRecord),
|
typeof(ContentItemVersionRecord),
|
||||||
typeof(ContentItemRecord),
|
typeof(ContentItemRecord),
|
||||||
typeof(ContentTypeRecord));
|
typeof(ContentTypeRecord));
|
||||||
@@ -65,7 +65,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
|||||||
.As(typeof(IMapper<SettingsDictionary, XElement>));
|
.As(typeof(IMapper<SettingsDictionary, XElement>));
|
||||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||||
builder.RegisterType<UserHandler>().As<IContentHandler>();
|
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||||
_session = _sessionFactory.OpenSession();
|
_session = _sessionFactory.OpenSession();
|
||||||
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
|
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
|
||||||
@@ -84,7 +84,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
|||||||
public void DefaultPasswordFormatShouldBeHashedAndHaveSalt() {
|
public void DefaultPasswordFormatShouldBeHashedAndHaveSalt() {
|
||||||
var user = _membershipService.CreateUser(new CreateUserParams("a", "b", "c", null, null, true));
|
var user = _membershipService.CreateUser(new CreateUserParams("a", "b", "c", null, null, true));
|
||||||
|
|
||||||
var userRepository = _container.Resolve<IRepository<UserRecord>>();
|
var userRepository = _container.Resolve<IRepository<UserPartRecord>>();
|
||||||
var userRecord = userRepository.Get(user.Id);
|
var userRecord = userRepository.Get(user.Id);
|
||||||
Assert.That(userRecord.PasswordFormat, Is.EqualTo(MembershipPasswordFormat.Hashed));
|
Assert.That(userRecord.PasswordFormat, Is.EqualTo(MembershipPasswordFormat.Hashed));
|
||||||
Assert.That(userRecord.Password, Is.Not.EqualTo("b"));
|
Assert.That(userRecord.Password, Is.Not.EqualTo("b"));
|
||||||
@@ -102,7 +102,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
|||||||
_session.Flush();
|
_session.Flush();
|
||||||
_session.Clear();
|
_session.Clear();
|
||||||
|
|
||||||
var userRepository = _container.Resolve<IRepository<UserRecord>>();
|
var userRepository = _container.Resolve<IRepository<UserPartRecord>>();
|
||||||
var user1Record = userRepository.Get(user1.Id);
|
var user1Record = userRepository.Get(user1.Id);
|
||||||
var user2Record = userRepository.Get(user2.Id);
|
var user2Record = userRepository.Get(user2.Id);
|
||||||
Assert.That(user1Record.PasswordSalt, Is.Not.EqualTo(user2Record.PasswordSalt));
|
Assert.That(user1Record.PasswordSalt, Is.Not.EqualTo(user2Record.PasswordSalt));
|
||||||
|
@@ -215,7 +215,7 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
SchemaBuilder.CreateTable("UserRecord", table =>
|
SchemaBuilder.CreateTable("UserPartRecord", table =>
|
||||||
table.Column("Id", DbType.Int32, column =>
|
table.Column("Id", DbType.Int32, column =>
|
||||||
column.PrimaryKey().Identity()));
|
column.PrimaryKey().Identity()));
|
||||||
|
|
||||||
|
@@ -33,13 +33,13 @@ namespace Orchard.Users.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var users = Services.ContentManager
|
var users = Services.ContentManager
|
||||||
.Query<User, UserRecord>()
|
.Query<UserPart, UserPartRecord>()
|
||||||
.Where(x => x.UserName != null)
|
.Where(x => x.UserName != null)
|
||||||
.List();
|
.List();
|
||||||
|
|
||||||
var model = new UsersIndexViewModel {
|
var model = new UsersIndexViewModel {
|
||||||
Rows = users
|
Rows = users
|
||||||
.Select(x => new UsersIndexViewModel.Row { User = x })
|
.Select(x => new UsersIndexViewModel.Row { UserPart = x })
|
||||||
.ToList()
|
.ToList()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ namespace Orchard.Users.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var user = Services.ContentManager.New<IUser>(UserDriver.ContentType.Name);
|
var user = Services.ContentManager.New<IUser>(UserPartDriver.ContentType.Name);
|
||||||
var model = new UserCreateViewModel {
|
var model = new UserCreateViewModel {
|
||||||
User = Services.ContentManager.BuildEditorModel(user)
|
User = Services.ContentManager.BuildEditorModel(user)
|
||||||
};
|
};
|
||||||
@@ -62,7 +62,7 @@ namespace Orchard.Users.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var user = Services.ContentManager.New<IUser>(UserDriver.ContentType.Name);
|
var user = Services.ContentManager.New<IUser>(UserPartDriver.ContentType.Name);
|
||||||
model.User = Services.ContentManager.UpdateEditorModel(user, this);
|
model.User = Services.ContentManager.UpdateEditorModel(user, this);
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
Services.TransactionManager.Cancel();
|
||||||
@@ -99,7 +99,7 @@ namespace Orchard.Users.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
return View(new UserEditViewModel {
|
return View(new UserEditViewModel {
|
||||||
User = Services.ContentManager.BuildEditorModel<User>(id)
|
User = Services.ContentManager.BuildEditorModel<UserPart>(id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ namespace Orchard.Users.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var model = new UserEditViewModel {
|
var model = new UserEditViewModel {
|
||||||
User = Services.ContentManager.UpdateEditorModel<User>(id, this)
|
User = Services.ContentManager.UpdateEditorModel<UserPart>(id, this)
|
||||||
};
|
};
|
||||||
|
|
||||||
TryUpdateModel(model);
|
TryUpdateModel(model);
|
||||||
|
@@ -5,7 +5,7 @@ namespace Orchard.Users.DataMigrations {
|
|||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
//CREATE TABLE Orchard_Users_UserRecord (Id INTEGER not null, UserName TEXT, Email TEXT, NormalizedUserName TEXT, Password TEXT, PasswordFormat TEXT, PasswordSalt TEXT, primary key (Id));
|
//CREATE TABLE Orchard_Users_UserRecord (Id INTEGER not null, UserName TEXT, Email TEXT, NormalizedUserName TEXT, Password TEXT, PasswordFormat TEXT, PasswordSalt TEXT, primary key (Id));
|
||||||
SchemaBuilder.CreateTable("UserRecord", table => table
|
SchemaBuilder.CreateTable("UserPartRecord", table => table
|
||||||
.ContentPartRecord()
|
.ContentPartRecord()
|
||||||
.Column<string>("UserName")
|
.Column<string>("UserName")
|
||||||
.Column<string>("Email")
|
.Column<string>("Email")
|
||||||
|
@@ -6,7 +6,7 @@ using Orchard.Users.Models;
|
|||||||
|
|
||||||
namespace Orchard.Users.Drivers {
|
namespace Orchard.Users.Drivers {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class UserDriver : ContentItemDriver<User> {
|
public class UserPartDriver : ContentItemDriver<UserPart> {
|
||||||
public readonly static ContentType ContentType = new ContentType {
|
public readonly static ContentType ContentType = new ContentType {
|
||||||
Name = "User",
|
Name = "User",
|
||||||
DisplayName = "User Profile"
|
DisplayName = "User Profile"
|
||||||
@@ -18,12 +18,12 @@ namespace Orchard.Users.Drivers {
|
|||||||
return ContentType;
|
return ContentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDisplayText(User item) {
|
protected override string GetDisplayText(UserPart item) {
|
||||||
//TEMP: need a "display name" probably... showing login info likely not a best practice...
|
//TEMP: need a "display name" probably... showing login info likely not a best practice...
|
||||||
return item.UserName;
|
return item.UserName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override RouteValueDictionary GetEditorRouteValues(User item) {
|
public override RouteValueDictionary GetEditorRouteValues(UserPart item) {
|
||||||
return new RouteValueDictionary {
|
return new RouteValueDictionary {
|
||||||
{"Area", "Orchard.Users"},
|
{"Area", "Orchard.Users"},
|
||||||
{"Controller", "Admin"},
|
{"Controller", "Admin"},
|
@@ -6,9 +6,9 @@ using Orchard.Users.Models;
|
|||||||
|
|
||||||
namespace Orchard.Users.Handlers {
|
namespace Orchard.Users.Handlers {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class UserHandler : ContentHandler {
|
public class UserPartHandler : ContentHandler {
|
||||||
public UserHandler(IRepository<UserRecord> repository) {
|
public UserPartHandler(IRepository<UserPartRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<User>(UserDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<UserPart>(UserPartDriver.ContentType.Name));
|
||||||
Filters.Add(StorageFilter.For(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,7 +2,7 @@
|
|||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
|
|
||||||
namespace Orchard.Users.Models {
|
namespace Orchard.Users.Models {
|
||||||
public sealed class User : ContentPart<UserRecord>, IUser {
|
public sealed class UserPart : ContentPart<UserPartRecord>, IUser {
|
||||||
public int Id {
|
public int Id {
|
||||||
get { return ContentItem.Id; }
|
get { return ContentItem.Id; }
|
||||||
}
|
}
|
@@ -2,7 +2,7 @@ using System.Web.Security;
|
|||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
|
|
||||||
namespace Orchard.Users.Models {
|
namespace Orchard.Users.Models {
|
||||||
public class UserRecord : ContentPartRecord {
|
public class UserPartRecord : ContentPartRecord {
|
||||||
public virtual string UserName { get; set; }
|
public virtual string UserName { get; set; }
|
||||||
public virtual string Email { get; set; }
|
public virtual string Email { get; set; }
|
||||||
public virtual string NormalizedUserName { get; set; }
|
public virtual string NormalizedUserName { get; set; }
|
@@ -68,10 +68,10 @@
|
|||||||
<Compile Include="Controllers\AccountController.cs" />
|
<Compile Include="Controllers\AccountController.cs" />
|
||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
<Compile Include="DataMigrations\UsersDataMigration.cs" />
|
<Compile Include="DataMigrations\UsersDataMigration.cs" />
|
||||||
<Compile Include="Drivers\UserDriver.cs" />
|
<Compile Include="Drivers\UserPartDriver.cs" />
|
||||||
<Compile Include="Models\User.cs" />
|
<Compile Include="Models\UserPart.cs" />
|
||||||
<Compile Include="Handlers\UserHandler.cs" />
|
<Compile Include="Handlers\UserPartHandler.cs" />
|
||||||
<Compile Include="Models\UserRecord.cs" />
|
<Compile Include="Models\UserPartRecord.cs" />
|
||||||
<Compile Include="Permissions.cs" />
|
<Compile Include="Permissions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Services\IUserService.cs" />
|
<Compile Include="Services\IUserService.cs" />
|
||||||
|
@@ -15,9 +15,9 @@ namespace Orchard.Users.Services {
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class MembershipService : IMembershipService {
|
public class MembershipService : IMembershipService {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly IRepository<UserRecord> _userRepository;
|
private readonly IRepository<UserPartRecord> _userRepository;
|
||||||
|
|
||||||
public MembershipService(IContentManager contentManager, IRepository<UserRecord> userRepository) {
|
public MembershipService(IContentManager contentManager, IRepository<UserPartRecord> userRepository) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
@@ -34,7 +34,7 @@ namespace Orchard.Users.Services {
|
|||||||
public IUser CreateUser(CreateUserParams createUserParams) {
|
public IUser CreateUser(CreateUserParams createUserParams) {
|
||||||
Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);
|
Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);
|
||||||
|
|
||||||
return _contentManager.Create<User>(UserDriver.ContentType.Name, init =>
|
return _contentManager.Create<UserPart>(UserPartDriver.ContentType.Name, init =>
|
||||||
{
|
{
|
||||||
init.Record.UserName = createUserParams.Username;
|
init.Record.UserName = createUserParams.Username;
|
||||||
init.Record.Email = createUserParams.Email;
|
init.Record.Email = createUserParams.Email;
|
||||||
@@ -69,57 +69,57 @@ namespace Orchard.Users.Services {
|
|||||||
|
|
||||||
|
|
||||||
public void SetPassword(IUser user, string password) {
|
public void SetPassword(IUser user, string password) {
|
||||||
if (!user.Is<User>())
|
if (!user.Is<UserPart>())
|
||||||
throw new InvalidCastException();
|
throw new InvalidCastException();
|
||||||
|
|
||||||
var userRecord = user.As<User>().Record;
|
var userRecord = user.As<UserPart>().Record;
|
||||||
SetPassword(userRecord, password);
|
SetPassword(userRecord, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetPassword(UserRecord record, string password) {
|
void SetPassword(UserPartRecord partRecord, string password) {
|
||||||
switch (GetSettings().PasswordFormat) {
|
switch (GetSettings().PasswordFormat) {
|
||||||
case MembershipPasswordFormat.Clear:
|
case MembershipPasswordFormat.Clear:
|
||||||
SetPasswordClear(record, password);
|
SetPasswordClear(partRecord, password);
|
||||||
break;
|
break;
|
||||||
case MembershipPasswordFormat.Hashed:
|
case MembershipPasswordFormat.Hashed:
|
||||||
SetPasswordHashed(record, password);
|
SetPasswordHashed(partRecord, password);
|
||||||
break;
|
break;
|
||||||
case MembershipPasswordFormat.Encrypted:
|
case MembershipPasswordFormat.Encrypted:
|
||||||
SetPasswordEncrypted(record, password);
|
SetPasswordEncrypted(partRecord, password);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ApplicationException("Unexpected password format value");
|
throw new ApplicationException("Unexpected password format value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ValidatePassword(UserRecord record, string password) {
|
private bool ValidatePassword(UserPartRecord partRecord, string password) {
|
||||||
// Note - the password format stored with the record is used
|
// Note - the password format stored with the record is used
|
||||||
// otherwise changing the password format on the site would invalidate
|
// otherwise changing the password format on the site would invalidate
|
||||||
// all logins
|
// all logins
|
||||||
switch (record.PasswordFormat) {
|
switch (partRecord.PasswordFormat) {
|
||||||
case MembershipPasswordFormat.Clear:
|
case MembershipPasswordFormat.Clear:
|
||||||
return ValidatePasswordClear(record, password);
|
return ValidatePasswordClear(partRecord, password);
|
||||||
case MembershipPasswordFormat.Hashed:
|
case MembershipPasswordFormat.Hashed:
|
||||||
return ValidatePasswordHashed(record, password);
|
return ValidatePasswordHashed(partRecord, password);
|
||||||
case MembershipPasswordFormat.Encrypted:
|
case MembershipPasswordFormat.Encrypted:
|
||||||
return ValidatePasswordEncrypted(record, password);
|
return ValidatePasswordEncrypted(partRecord, password);
|
||||||
default:
|
default:
|
||||||
throw new ApplicationException("Unexpected password format value");
|
throw new ApplicationException("Unexpected password format value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetPasswordClear(UserRecord record, string password) {
|
private static void SetPasswordClear(UserPartRecord partRecord, string password) {
|
||||||
record.PasswordFormat = MembershipPasswordFormat.Clear;
|
partRecord.PasswordFormat = MembershipPasswordFormat.Clear;
|
||||||
record.Password = password;
|
partRecord.Password = password;
|
||||||
record.PasswordSalt = null;
|
partRecord.PasswordSalt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ValidatePasswordClear(UserRecord record, string password) {
|
private static bool ValidatePasswordClear(UserPartRecord partRecord, string password) {
|
||||||
return record.Password == password;
|
return partRecord.Password == password;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetPasswordHashed(UserRecord record, string password) {
|
private static void SetPasswordHashed(UserPartRecord partRecord, string password) {
|
||||||
|
|
||||||
var saltBytes = new byte[0x10];
|
var saltBytes = new byte[0x10];
|
||||||
var random = new RNGCryptoServiceProvider();
|
var random = new RNGCryptoServiceProvider();
|
||||||
@@ -129,33 +129,33 @@ namespace Orchard.Users.Services {
|
|||||||
|
|
||||||
var combinedBytes = saltBytes.Concat(passwordBytes).ToArray();
|
var combinedBytes = saltBytes.Concat(passwordBytes).ToArray();
|
||||||
|
|
||||||
var hashAlgorithm = HashAlgorithm.Create(record.HashAlgorithm);
|
var hashAlgorithm = HashAlgorithm.Create(partRecord.HashAlgorithm);
|
||||||
var hashBytes = hashAlgorithm.ComputeHash(combinedBytes);
|
var hashBytes = hashAlgorithm.ComputeHash(combinedBytes);
|
||||||
|
|
||||||
record.PasswordFormat = MembershipPasswordFormat.Hashed;
|
partRecord.PasswordFormat = MembershipPasswordFormat.Hashed;
|
||||||
record.Password = Convert.ToBase64String(hashBytes);
|
partRecord.Password = Convert.ToBase64String(hashBytes);
|
||||||
record.PasswordSalt = Convert.ToBase64String(saltBytes);
|
partRecord.PasswordSalt = Convert.ToBase64String(saltBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ValidatePasswordHashed(UserRecord record, string password) {
|
private static bool ValidatePasswordHashed(UserPartRecord partRecord, string password) {
|
||||||
|
|
||||||
var saltBytes = Convert.FromBase64String(record.PasswordSalt);
|
var saltBytes = Convert.FromBase64String(partRecord.PasswordSalt);
|
||||||
|
|
||||||
var passwordBytes = Encoding.Unicode.GetBytes(password);
|
var passwordBytes = Encoding.Unicode.GetBytes(password);
|
||||||
|
|
||||||
var combinedBytes = saltBytes.Concat(passwordBytes).ToArray();
|
var combinedBytes = saltBytes.Concat(passwordBytes).ToArray();
|
||||||
|
|
||||||
var hashAlgorithm = HashAlgorithm.Create(record.HashAlgorithm);
|
var hashAlgorithm = HashAlgorithm.Create(partRecord.HashAlgorithm);
|
||||||
var hashBytes = hashAlgorithm.ComputeHash(combinedBytes);
|
var hashBytes = hashAlgorithm.ComputeHash(combinedBytes);
|
||||||
|
|
||||||
return record.Password == Convert.ToBase64String(hashBytes);
|
return partRecord.Password == Convert.ToBase64String(hashBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetPasswordEncrypted(UserRecord record, string password) {
|
private static void SetPasswordEncrypted(UserPartRecord partRecord, string password) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ValidatePasswordEncrypted(UserRecord record, string password) {
|
private static bool ValidatePasswordEncrypted(UserPartRecord partRecord, string password) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ namespace Orchard.Users.Services {
|
|||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
public string VerifyUserUnicity(string userName, string email) {
|
public string VerifyUserUnicity(string userName, string email) {
|
||||||
IEnumerable<User> allUsers = _contentManager.Query<User, UserRecord>().List();
|
IEnumerable<UserPart> allUsers = _contentManager.Query<UserPart, UserPartRecord>().List();
|
||||||
|
|
||||||
foreach (var user in allUsers) {
|
foreach (var user in allUsers) {
|
||||||
if (String.Equals(userName.ToLower(), user.NormalizedUserName, StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(userName.ToLower(), user.NormalizedUserName, StringComparison.OrdinalIgnoreCase)) {
|
||||||
@@ -33,7 +33,7 @@ namespace Orchard.Users.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string VerifyUserUnicity(int id, string userName, string email) {
|
public string VerifyUserUnicity(int id, string userName, string email) {
|
||||||
IEnumerable<User> allUsers = _contentManager.Query<User, UserRecord>().List();
|
IEnumerable<UserPart> allUsers = _contentManager.Query<UserPart, UserPartRecord>().List();
|
||||||
foreach (var user in allUsers) {
|
foreach (var user in allUsers) {
|
||||||
if (user.Id == id)
|
if (user.Id == id)
|
||||||
continue;
|
continue;
|
||||||
|
@@ -23,6 +23,6 @@ namespace Orchard.Users.ViewModels {
|
|||||||
set { User.Item.Record.Email = value; }
|
set { User.Item.Record.Email = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItemViewModel<User> User { get; set; }
|
public ContentItemViewModel<UserPart> User { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -6,7 +6,7 @@ namespace Orchard.Users.ViewModels {
|
|||||||
|
|
||||||
public class UsersIndexViewModel : BaseViewModel {
|
public class UsersIndexViewModel : BaseViewModel {
|
||||||
public class Row {
|
public class Row {
|
||||||
public User User { get; set; }
|
public UserPart UserPart { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public IList<Row> Rows { get; set; }
|
public IList<Row> Rows { get; set; }
|
||||||
|
@@ -22,14 +22,14 @@
|
|||||||
{ %>
|
{ %>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<%: row.User.UserName %>
|
<%: row.UserPart.UserName %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%: row.User.Email %>
|
<%: row.UserPart.Email %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%: Html.ActionLink(T("Edit").ToString(), "Edit", new { row.User.Id })%> |
|
<%: Html.ActionLink(T("Edit").ToString(), "Edit", new { row.UserPart.Id })%> |
|
||||||
<%: Html.ActionLink(T("Remove").ToString(), "Delete", new { row.User.Id })%>
|
<%: Html.ActionLink(T("Remove").ToString(), "Delete", new { row.UserPart.Id })%>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<%}%>
|
<%}%>
|
||||||
|
Reference in New Issue
Block a user