Updates the underlying UmbracoServiceMembershipProvider to deal with 'object' for provider key, this then lets us deal with either guid or int for the new membership provider, just like the old one does.

This commit is contained in:
Shannon
2014-02-17 14:14:17 +11:00
parent 10ef5eb7bc
commit 509be9b431
8 changed files with 43 additions and 24 deletions

View File

@@ -24,6 +24,13 @@ namespace Umbraco.Core.Services
/// <returns></returns>
IMember GetByKey(Guid id);
/// <summary>
/// Gets a member by it's id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
IMember GetById(int id);
/// <summary>
/// Get all members for the member type alias
/// </summary>

View File

@@ -50,7 +50,12 @@ namespace Umbraco.Core.Services
/// <returns></returns>
T CreateMemberWithIdentity(string username, string email, string password, string memberTypeAlias, bool raiseEvents = true);
T GetById(int id);
/// <summary>
/// Gets the member by the provider key
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T GetByProviderKey(object id);
/// <summary>
/// Get a member by email

View File

@@ -642,17 +642,18 @@ namespace Umbraco.Core.Services
/// </remarks>
/// <param name="id"></param>
/// <returns></returns>
public IMember GetById(object id)
public IMember GetByProviderKey(object id)
{
if (id is int)
{
return GetById((int)id);
}
if (id is Guid)
var asGuid = id.TryConvertTo<Guid>();
if (asGuid.Success)
{
return GetByKey((Guid)id);
}
var asInt = id.TryConvertTo<int>();
if (asInt.Success)
{
return GetById((int)id);
}
return null;
}

View File

@@ -140,6 +140,17 @@ namespace Umbraco.Core.Services
}
}
public IUser GetByProviderKey(object id)
{
var asInt = id.TryConvertTo<int>();
if (asInt.Success)
{
return GetById((int)id);
}
return null;
}
public IUser GetByEmail(string email)
{
using (var repository = _repositoryFactory.CreateUserRepository(_uowProvider.GetUnitOfWork()))

View File

@@ -100,7 +100,7 @@ namespace Umbraco.Tests.Services
var user = ServiceContext.UserService.CreateMemberWithIdentity("JohnDoe", "john@umbraco.io", "12345", userType);
ServiceContext.UserService.Delete(user, true);
var deleted = ServiceContext.UserService.GetById(user.Id);
var deleted = ServiceContext.UserService.GetUserById(user.Id);
// Assert
Assert.That(deleted, Is.Null);
@@ -114,7 +114,7 @@ namespace Umbraco.Tests.Services
var user = ServiceContext.UserService.CreateMemberWithIdentity("JohnDoe", "john@umbraco.io", "12345", userType);
ServiceContext.UserService.Delete(user);
var deleted = ServiceContext.UserService.GetById(user.Id);
var deleted = ServiceContext.UserService.GetUserById(user.Id);
// Assert
Assert.That(deleted, Is.Not.Null);
@@ -160,8 +160,8 @@ namespace Umbraco.Tests.Services
ServiceContext.UserService.SaveUserType(userType);
var user = ServiceContext.UserService.CreateMemberWithIdentity("JohnDoe", "john@umbraco.io", "12345", userType);
Assert.IsNotNull(ServiceContext.UserService.GetById(user.Id));
Assert.IsNull(ServiceContext.UserService.GetById(9876));
Assert.IsNotNull(ServiceContext.UserService.GetUserById(user.Id));
Assert.IsNull(ServiceContext.UserService.GetUserById(9876));
}
[Test]

View File

@@ -346,12 +346,7 @@ namespace Umbraco.Web.Security.Providers
/// </returns>
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
if ((providerUserKey is int) == false)
{
return null;
}
var member = MemberService.GetById((int)providerUserKey);
var member = MemberService.GetByProviderKey(providerUserKey);
if (member == null)
{
return null;

View File

@@ -79,7 +79,7 @@ namespace umbraco.BusinessLogic
private void SetupUser(int ID)
{
_user = ApplicationContext.Current.Services.UserService.GetById(ID);
_user = ApplicationContext.Current.Services.UserService.GetUserById(ID);
if (_user == null)
{
throw new ArgumentException("No User exists with ID " + ID);
@@ -496,7 +496,7 @@ namespace umbraco.BusinessLogic
if (EnsureUniqueLoginName(lname, GetUser(id)) == false)
throw new Exception(String.Format("A user with the login '{0}' already exists", lname));
var found = ApplicationContext.Current.Services.UserService.GetById(id);
var found = ApplicationContext.Current.Services.UserService.GetUserById(id);
if (found == null) return;
found.Name = name;
found.Username = lname;
@@ -510,7 +510,7 @@ namespace umbraco.BusinessLogic
if (EnsureUniqueLoginName(lname, GetUser(id)) == false)
throw new Exception(String.Format("A user with the login '{0}' already exists", lname));
var found = ApplicationContext.Current.Services.UserService.GetById(id);
var found = ApplicationContext.Current.Services.UserService.GetUserById(id);
if (found == null) return;
found.Name = name;
found.Username = lname;
@@ -530,7 +530,7 @@ namespace umbraco.BusinessLogic
/// <param name="noConsole"></param>
public static void Update(int id, string email, bool disabled, bool noConsole)
{
var found = ApplicationContext.Current.Services.UserService.GetById(id);
var found = ApplicationContext.Current.Services.UserService.GetUserById(id);
if (found == null) return;
found.Email = email;
@@ -822,7 +822,7 @@ namespace umbraco.BusinessLogic
/// <returns></returns>
public static User GetUser(int id)
{
var result = ApplicationContext.Current.Services.UserService.GetById(id);
var result = ApplicationContext.Current.Services.UserService.GetUserById(id);
if (result == null)
{
throw new ArgumentException("No user found with id " + id);

View File

@@ -77,7 +77,7 @@ namespace umbraco.cms.businesslogic.workflow
private static void SendNotification(User performingUser, User mailingUser, Document documentObject, IAction action)
{
var nService = ApplicationContext.Current.Services.NotificationService;
var pUser = ApplicationContext.Current.Services.UserService.GetById(performingUser.Id);
var pUser = ApplicationContext.Current.Services.UserService.GetUserById(performingUser.Id);
nService.SendNotifications(
pUser, documentObject.Content, action.Letter.ToString(CultureInfo.InvariantCulture), ui.Text(action.Alias),