mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +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<MembershipService>().As<IMembershipService>();
|
||||
builder.RegisterType<UserService>().As<IUserService>();
|
||||
builder.RegisterType<UserHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
|
||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||
@@ -53,7 +53,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
||||
|
||||
protected override IEnumerable<Type> DatabaseTypes {
|
||||
get {
|
||||
return new[] { typeof(UserRecord),
|
||||
return new[] { typeof(UserPartRecord),
|
||||
typeof(ContentTypeRecord),
|
||||
typeof(ContentItemRecord),
|
||||
typeof(ContentItemVersionRecord),
|
||||
@@ -66,16 +66,16 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
||||
|
||||
var manager = _container.Resolve<IContentManager>();
|
||||
|
||||
var userOne = manager.New<User>("User");
|
||||
userOne.Record = new UserRecord { UserName = "one" };
|
||||
var userOne = manager.New<UserPart>("User");
|
||||
userOne.Record = new UserPartRecord { UserName = "one" };
|
||||
manager.Create(userOne.ContentItem);
|
||||
|
||||
var userTwo = manager.New<User>("User");
|
||||
userTwo.Record = new UserRecord { UserName = "two" };
|
||||
var userTwo = manager.New<UserPart>("User");
|
||||
userTwo.Record = new UserPartRecord { UserName = "two" };
|
||||
manager.Create(userTwo.ContentItem);
|
||||
|
||||
var userThree = manager.New<User>("User");
|
||||
userThree.Record = new UserRecord { UserName = "three" };
|
||||
var userThree = manager.New<UserPart>("User");
|
||||
userThree.Record = new UserPartRecord { UserName = "three" };
|
||||
manager.Create(userThree.ContentItem);
|
||||
|
||||
_controller = _container.Resolve<AdminController>();
|
||||
@@ -125,7 +125,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
||||
public void EditShouldDisplayUserAndStoreChanges() {
|
||||
_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 result = (ViewResult)_container.Resolve<AdminController>().Edit(id);
|
||||
var model = (UserEditViewModel)result.ViewData.Model;
|
||||
|
@@ -43,7 +43,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
var databaseFileName = System.IO.Path.GetTempFileName();
|
||||
_sessionFactory = DataUtility.CreateSessionFactory(
|
||||
databaseFileName,
|
||||
typeof(UserRecord),
|
||||
typeof(UserPartRecord),
|
||||
typeof(ContentItemVersionRecord),
|
||||
typeof(ContentItemRecord),
|
||||
typeof(ContentTypeRecord));
|
||||
@@ -65,7 +65,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
.As(typeof(IMapper<SettingsDictionary, XElement>));
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<UserHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||
_session = _sessionFactory.OpenSession();
|
||||
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
|
||||
@@ -84,7 +84,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
public void DefaultPasswordFormatShouldBeHashedAndHaveSalt() {
|
||||
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);
|
||||
Assert.That(userRecord.PasswordFormat, Is.EqualTo(MembershipPasswordFormat.Hashed));
|
||||
Assert.That(userRecord.Password, Is.Not.EqualTo("b"));
|
||||
@@ -102,7 +102,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
_session.Flush();
|
||||
_session.Clear();
|
||||
|
||||
var userRepository = _container.Resolve<IRepository<UserRecord>>();
|
||||
var userRepository = _container.Resolve<IRepository<UserPartRecord>>();
|
||||
var user1Record = userRepository.Get(user1.Id);
|
||||
var user2Record = userRepository.Get(user2.Id);
|
||||
Assert.That(user1Record.PasswordSalt, Is.Not.EqualTo(user2Record.PasswordSalt));
|
||||
|
@@ -215,7 +215,7 @@ namespace Orchard.Tests.DataMigration {
|
||||
}
|
||||
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("UserRecord", table =>
|
||||
SchemaBuilder.CreateTable("UserPartRecord", table =>
|
||||
table.Column("Id", DbType.Int32, column =>
|
||||
column.PrimaryKey().Identity()));
|
||||
|
||||
|
@@ -33,13 +33,13 @@ namespace Orchard.Users.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var users = Services.ContentManager
|
||||
.Query<User, UserRecord>()
|
||||
.Query<UserPart, UserPartRecord>()
|
||||
.Where(x => x.UserName != null)
|
||||
.List();
|
||||
|
||||
var model = new UsersIndexViewModel {
|
||||
Rows = users
|
||||
.Select(x => new UsersIndexViewModel.Row { User = x })
|
||||
.Select(x => new UsersIndexViewModel.Row { UserPart = x })
|
||||
.ToList()
|
||||
};
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Orchard.Users.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
|
||||
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 {
|
||||
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")))
|
||||
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);
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
@@ -99,7 +99,7 @@ namespace Orchard.Users.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
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();
|
||||
|
||||
var model = new UserEditViewModel {
|
||||
User = Services.ContentManager.UpdateEditorModel<User>(id, this)
|
||||
User = Services.ContentManager.UpdateEditorModel<UserPart>(id, this)
|
||||
};
|
||||
|
||||
TryUpdateModel(model);
|
||||
|
@@ -5,7 +5,7 @@ namespace Orchard.Users.DataMigrations {
|
||||
|
||||
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));
|
||||
SchemaBuilder.CreateTable("UserRecord", table => table
|
||||
SchemaBuilder.CreateTable("UserPartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("UserName")
|
||||
.Column<string>("Email")
|
||||
|
@@ -6,7 +6,7 @@ using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class UserDriver : ContentItemDriver<User> {
|
||||
public class UserPartDriver : ContentItemDriver<UserPart> {
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "User",
|
||||
DisplayName = "User Profile"
|
||||
@@ -18,12 +18,12 @@ namespace Orchard.Users.Drivers {
|
||||
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...
|
||||
return item.UserName;
|
||||
}
|
||||
|
||||
public override RouteValueDictionary GetEditorRouteValues(User item) {
|
||||
public override RouteValueDictionary GetEditorRouteValues(UserPart item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Orchard.Users"},
|
||||
{"Controller", "Admin"},
|
@@ -6,9 +6,9 @@ using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Users.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class UserHandler : ContentHandler {
|
||||
public UserHandler(IRepository<UserRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<User>(UserDriver.ContentType.Name));
|
||||
public class UserPartHandler : ContentHandler {
|
||||
public UserPartHandler(IRepository<UserPartRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<UserPart>(UserPartDriver.ContentType.Name));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Users.Models {
|
||||
public sealed class User : ContentPart<UserRecord>, IUser {
|
||||
public sealed class UserPart : ContentPart<UserPartRecord>, IUser {
|
||||
public int Id {
|
||||
get { return ContentItem.Id; }
|
||||
}
|
@@ -2,7 +2,7 @@ using System.Web.Security;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Users.Models {
|
||||
public class UserRecord : ContentPartRecord {
|
||||
public class UserPartRecord : ContentPartRecord {
|
||||
public virtual string UserName { get; set; }
|
||||
public virtual string Email { get; set; }
|
||||
public virtual string NormalizedUserName { get; set; }
|
@@ -68,10 +68,10 @@
|
||||
<Compile Include="Controllers\AccountController.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="DataMigrations\UsersDataMigration.cs" />
|
||||
<Compile Include="Drivers\UserDriver.cs" />
|
||||
<Compile Include="Models\User.cs" />
|
||||
<Compile Include="Handlers\UserHandler.cs" />
|
||||
<Compile Include="Models\UserRecord.cs" />
|
||||
<Compile Include="Drivers\UserPartDriver.cs" />
|
||||
<Compile Include="Models\UserPart.cs" />
|
||||
<Compile Include="Handlers\UserPartHandler.cs" />
|
||||
<Compile Include="Models\UserPartRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\IUserService.cs" />
|
||||
|
@@ -15,9 +15,9 @@ namespace Orchard.Users.Services {
|
||||
[UsedImplicitly]
|
||||
public class MembershipService : IMembershipService {
|
||||
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;
|
||||
_userRepository = userRepository;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -34,7 +34,7 @@ namespace Orchard.Users.Services {
|
||||
public IUser CreateUser(CreateUserParams createUserParams) {
|
||||
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.Email = createUserParams.Email;
|
||||
@@ -69,57 +69,57 @@ namespace Orchard.Users.Services {
|
||||
|
||||
|
||||
public void SetPassword(IUser user, string password) {
|
||||
if (!user.Is<User>())
|
||||
if (!user.Is<UserPart>())
|
||||
throw new InvalidCastException();
|
||||
|
||||
var userRecord = user.As<User>().Record;
|
||||
var userRecord = user.As<UserPart>().Record;
|
||||
SetPassword(userRecord, password);
|
||||
}
|
||||
|
||||
|
||||
void SetPassword(UserRecord record, string password) {
|
||||
void SetPassword(UserPartRecord partRecord, string password) {
|
||||
switch (GetSettings().PasswordFormat) {
|
||||
case MembershipPasswordFormat.Clear:
|
||||
SetPasswordClear(record, password);
|
||||
SetPasswordClear(partRecord, password);
|
||||
break;
|
||||
case MembershipPasswordFormat.Hashed:
|
||||
SetPasswordHashed(record, password);
|
||||
SetPasswordHashed(partRecord, password);
|
||||
break;
|
||||
case MembershipPasswordFormat.Encrypted:
|
||||
SetPasswordEncrypted(record, password);
|
||||
SetPasswordEncrypted(partRecord, password);
|
||||
break;
|
||||
default:
|
||||
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
|
||||
// otherwise changing the password format on the site would invalidate
|
||||
// all logins
|
||||
switch (record.PasswordFormat) {
|
||||
switch (partRecord.PasswordFormat) {
|
||||
case MembershipPasswordFormat.Clear:
|
||||
return ValidatePasswordClear(record, password);
|
||||
return ValidatePasswordClear(partRecord, password);
|
||||
case MembershipPasswordFormat.Hashed:
|
||||
return ValidatePasswordHashed(record, password);
|
||||
return ValidatePasswordHashed(partRecord, password);
|
||||
case MembershipPasswordFormat.Encrypted:
|
||||
return ValidatePasswordEncrypted(record, password);
|
||||
return ValidatePasswordEncrypted(partRecord, password);
|
||||
default:
|
||||
throw new ApplicationException("Unexpected password format value");
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetPasswordClear(UserRecord record, string password) {
|
||||
record.PasswordFormat = MembershipPasswordFormat.Clear;
|
||||
record.Password = password;
|
||||
record.PasswordSalt = null;
|
||||
private static void SetPasswordClear(UserPartRecord partRecord, string password) {
|
||||
partRecord.PasswordFormat = MembershipPasswordFormat.Clear;
|
||||
partRecord.Password = password;
|
||||
partRecord.PasswordSalt = null;
|
||||
}
|
||||
|
||||
private static bool ValidatePasswordClear(UserRecord record, string password) {
|
||||
return record.Password == password;
|
||||
private static bool ValidatePasswordClear(UserPartRecord partRecord, string 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 random = new RNGCryptoServiceProvider();
|
||||
@@ -129,33 +129,33 @@ namespace Orchard.Users.Services {
|
||||
|
||||
var combinedBytes = saltBytes.Concat(passwordBytes).ToArray();
|
||||
|
||||
var hashAlgorithm = HashAlgorithm.Create(record.HashAlgorithm);
|
||||
var hashAlgorithm = HashAlgorithm.Create(partRecord.HashAlgorithm);
|
||||
var hashBytes = hashAlgorithm.ComputeHash(combinedBytes);
|
||||
|
||||
record.PasswordFormat = MembershipPasswordFormat.Hashed;
|
||||
record.Password = Convert.ToBase64String(hashBytes);
|
||||
record.PasswordSalt = Convert.ToBase64String(saltBytes);
|
||||
partRecord.PasswordFormat = MembershipPasswordFormat.Hashed;
|
||||
partRecord.Password = Convert.ToBase64String(hashBytes);
|
||||
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 combinedBytes = saltBytes.Concat(passwordBytes).ToArray();
|
||||
|
||||
var hashAlgorithm = HashAlgorithm.Create(record.HashAlgorithm);
|
||||
var hashAlgorithm = HashAlgorithm.Create(partRecord.HashAlgorithm);
|
||||
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();
|
||||
}
|
||||
|
||||
private static bool ValidatePasswordEncrypted(UserRecord record, string password) {
|
||||
private static bool ValidatePasswordEncrypted(UserPartRecord partRecord, string password) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ namespace Orchard.Users.Services {
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
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) {
|
||||
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) {
|
||||
IEnumerable<User> allUsers = _contentManager.Query<User, UserRecord>().List();
|
||||
IEnumerable<UserPart> allUsers = _contentManager.Query<UserPart, UserPartRecord>().List();
|
||||
foreach (var user in allUsers) {
|
||||
if (user.Id == id)
|
||||
continue;
|
||||
|
@@ -23,6 +23,6 @@ namespace Orchard.Users.ViewModels {
|
||||
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 Row {
|
||||
public User User { get; set; }
|
||||
public UserPart UserPart { get; set; }
|
||||
}
|
||||
|
||||
public IList<Row> Rows { get; set; }
|
||||
|
@@ -22,14 +22,14 @@
|
||||
{ %>
|
||||
<tr>
|
||||
<td>
|
||||
<%: row.User.UserName %>
|
||||
<%: row.UserPart.UserName %>
|
||||
</td>
|
||||
<td>
|
||||
<%: row.User.Email %>
|
||||
<%: row.UserPart.Email %>
|
||||
</td>
|
||||
<td>
|
||||
<%: Html.ActionLink(T("Edit").ToString(), "Edit", new { row.User.Id })%> |
|
||||
<%: Html.ActionLink(T("Remove").ToString(), "Delete", new { row.User.Id })%>
|
||||
<%: Html.ActionLink(T("Edit").ToString(), "Edit", new { row.UserPart.Id })%> |
|
||||
<%: Html.ActionLink(T("Remove").ToString(), "Delete", new { row.UserPart.Id })%>
|
||||
</td>
|
||||
</tr>
|
||||
<%}%>
|
||||
|
Reference in New Issue
Block a user