Starts the implementation of the new role provider.

This commit is contained in:
Shannon
2014-01-28 12:48:41 +11:00
parent a7298e2e5a
commit 7a99ebd6d9
5 changed files with 110 additions and 12 deletions

View File

@@ -6,14 +6,13 @@ using Umbraco.Core.Persistence.Querying;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines part of the MemberService, which is specific to methods used by the membership provider.
/// </summary>
/// <remarks>
/// Idea is to have this is an isolated interface so that it can be easily 'replaced' in the membership provider impl.
/// </remarks>
public interface IMembershipMemberService : IMembershipMemberService<IMember>
public interface IMembershipMemberService : IMembershipMemberService<IMember>, IMembershipRoleService<IMember>
{
IMember CreateMemberWithIdentity(string username, string email, string password, IMemberType memberType, bool raiseEvents = true);
}

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence.Querying;
namespace Umbraco.Core.Services
{
public interface IMembershipRoleService<out T>
where T : class, IMembershipUser
{
void AddRole(string roleName);
IEnumerable<string> GetAllRoles();
IEnumerable<string> GetAllRoles(int memberId);
IEnumerable<string> GetAllRoles(string username);
IEnumerable<T> GetMembersInRole(string roleName);
IEnumerable<T> FindMembersInRole(string roleName, string usernameToMatch, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith);
bool DeleteRole(string roleName, bool throwIfBeingUsed);
void AssignRoles(string[] usernames, string[] roleNames);
void DissociateRoles(string[] usernames, string[] roleNames);
void AssignRoles(int[] memberIds, string[] roleNames);
void DissociateRoles(int[] memberIds, string[] roleNames);
}
}

View File

@@ -765,6 +765,64 @@ namespace Umbraco.Core.Services
#endregion
#region IMembershipRoleService Implementation
public void AddRole(string roleName)
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllRoles()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllRoles(int memberId)
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllRoles(string username)
{
throw new NotImplementedException();
}
public IEnumerable<IMember> GetMembersInRole(string roleName)
{
throw new NotImplementedException();
}
public IEnumerable<IMember> FindMembersInRole(string roleName, string usernameToMatch, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith)
{
throw new NotImplementedException();
}
public bool DeleteRole(string roleName, bool throwIfBeingUsed)
{
throw new NotImplementedException();
}
public void AssignRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public void DissociateRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public void AssignRoles(int[] memberIds, string[] roleNames)
{
throw new NotImplementedException();
}
public void DissociateRoles(int[] memberIds, string[] roleNames)
{
throw new NotImplementedException();
}
#endregion
/// <summary>
/// Rebuilds all xml content in the cmsContentXml table for all media
/// </summary>
@@ -938,5 +996,6 @@ namespace Umbraco.Core.Services
// return new Member(name, email, username, password, -1, memType);
//}
}
}

View File

@@ -771,6 +771,7 @@
<Compile Include="Services\IMediaService.cs" />
<Compile Include="Services\IMemberService.cs" />
<Compile Include="Services\IMembershipMemberService.cs" />
<Compile Include="Services\IMembershipRoleService.cs" />
<Compile Include="Services\IMembershipUserService.cs" />
<Compile Include="Services\IMemberTypeService.cs" />
<Compile Include="Services\INotificationService.cs" />

View File

@@ -1,59 +1,76 @@
using System.Linq;
using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Services;
namespace Umbraco.Web.Security.Providers
{
public class MembersRoleProvider : RoleProvider
{
private readonly IMembershipRoleService<IMember> _roleService;
public MembersRoleProvider(IMembershipRoleService<IMember> roleService)
{
_roleService = roleService;
}
public MembersRoleProvider()
: this(ApplicationContext.Current.Services.MemberService)
{
}
private string _applicationName;
public override bool IsUserInRole(string username, string roleName)
{
throw new System.NotImplementedException();
return GetRolesForUser(username).Any(x => x == roleName);
}
public override string[] GetRolesForUser(string username)
{
throw new System.NotImplementedException();
return _roleService.GetAllRoles(username).ToArray();
}
public override void CreateRole(string roleName)
{
throw new System.NotImplementedException();
_roleService.AddRole(roleName);
}
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
{
throw new System.NotImplementedException();
return _roleService.DeleteRole(roleName, throwOnPopulatedRole);
}
public override bool RoleExists(string roleName)
{
throw new System.NotImplementedException();
return _roleService.GetAllRoles().Any(x => x == roleName);
}
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
{
throw new System.NotImplementedException();
_roleService.AssignRoles(usernames, roleNames);
}
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
{
throw new System.NotImplementedException();
_roleService.DissociateRoles(usernames, roleNames);
}
public override string[] GetUsersInRole(string roleName)
{
throw new System.NotImplementedException();
return _roleService.GetMembersInRole(roleName).Select(x => x.Username).ToArray();
}
public override string[] GetAllRoles()
{
throw new System.NotImplementedException();
return _roleService.GetAllRoles().ToArray();
}
public override string[] FindUsersInRole(string roleName, string usernameToMatch)
{
throw new System.NotImplementedException();
return _roleService.FindMembersInRole(roleName, usernameToMatch, StringPropertyMatchType.Wildcard).Select(x => x.Username).ToArray();
}
public override string ApplicationName