mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#19713: Adding identity resolvers for Layers and Users
Work Item: 19713 --HG-- branch : 1.x
This commit is contained in:
@@ -79,6 +79,7 @@
|
|||||||
<Compile Include="Models\UserStatus.cs" />
|
<Compile Include="Models\UserStatus.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Services\IUserService.cs" />
|
<Compile Include="Services\IUserService.cs" />
|
||||||
|
<Compile Include="Services\UserResolverSelector.cs" />
|
||||||
<Compile Include="Services\MembershipService.cs" />
|
<Compile Include="Services\MembershipService.cs" />
|
||||||
<Compile Include="AdminMenu.cs" />
|
<Compile Include="AdminMenu.cs" />
|
||||||
<Compile Include="Services\MissingSettingsBanner.cs" />
|
<Compile Include="Services\MissingSettingsBanner.cs" />
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Users.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Users.Services {
|
||||||
|
public class UserResolverSelector : IIdentityResolverSelector {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public UserResolverSelector(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
var comparer = new ContentIdentity.ContentIdentityEqualityComparer();
|
||||||
|
return _contentManager
|
||||||
|
.Query<UserPart, UserPartRecord>()
|
||||||
|
.Where(p => p.UserName == identifier)
|
||||||
|
.List<ContentItem>()
|
||||||
|
.Where(c => comparer.Equals(identity, _contentManager.GetItemMetadata(c).Identity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -85,6 +85,7 @@
|
|||||||
<Compile Include="Services\IRuleManager.cs" />
|
<Compile Include="Services\IRuleManager.cs" />
|
||||||
<Compile Include="Services\IRuleProvider.cs" />
|
<Compile Include="Services\IRuleProvider.cs" />
|
||||||
<Compile Include="Services\IWidgetsService.cs" />
|
<Compile Include="Services\IWidgetsService.cs" />
|
||||||
|
<Compile Include="Services\LayerResolverSelector.cs" />
|
||||||
<Compile Include="Services\RuleContext.cs" />
|
<Compile Include="Services\RuleContext.cs" />
|
||||||
<Compile Include="Services\WidgetsService.cs" />
|
<Compile Include="Services\WidgetsService.cs" />
|
||||||
<Compile Include="Shapes.cs" />
|
<Compile Include="Shapes.cs" />
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Widgets.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Widgets.Services {
|
||||||
|
public class LayerResolverSelector : IIdentityResolverSelector {
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public LayerResolverSelector(IContentManager contentManager) {
|
||||||
|
_contentManager = contentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityResolverSelectorResult GetResolver(ContentIdentity contentIdentity) {
|
||||||
|
if (contentIdentity.Has("Layer.LayerName")) {
|
||||||
|
return new IdentityResolverSelectorResult {
|
||||||
|
Priority = 0,
|
||||||
|
Resolve = ResolveIdentity
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<ContentItem> ResolveIdentity(ContentIdentity identity) {
|
||||||
|
var identifier = identity.Get("Layer.LayerName");
|
||||||
|
|
||||||
|
if (identifier == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var comparer = new ContentIdentity.ContentIdentityEqualityComparer();
|
||||||
|
return _contentManager
|
||||||
|
.Query<LayerPart, LayerPartRecord>()
|
||||||
|
.Where(p => p.Name == identifier)
|
||||||
|
.List<ContentItem>()
|
||||||
|
.Where(c => comparer.Equals(identity, _contentManager.GetItemMetadata(c).Identity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user