mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Adding User identity resolver
To improve import step for Users
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\AuthenticationRedirectionFilter.cs" />
|
||||
<Compile Include="Services\IUserService.cs" />
|
||||
<Compile Include="Services\UserNameIdentityResolver.cs" />
|
||||
<Compile Include="Services\UserResolverSelector.cs" />
|
||||
<Compile Include="Services\MembershipService.cs" />
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
|
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
namespace Orchard.Gallery.Services {
|
||||
public class PackageIdentityResolverSelector : IIdentityResolverSelector {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public PackageIdentityResolverSelector(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public IdentityResolverSelectorResult GetResolver(ContentIdentity contentIdentity) {
|
||||
if (contentIdentity.Has("User.UserName")) {
|
||||
return new IdentityResolverSelectorResult {
|
||||
Priority = 0,
|
||||
Resolve = ResolveIdentity
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) {
|
||||
var identifier = identity.Get("User.UserName");
|
||||
|
||||
if (identifier == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _contentManager
|
||||
.Query<UserPart, UserPartRecord>()
|
||||
.Where(p => p.NormalizedUserName == identifier)
|
||||
.List<ContentItem>();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user