diff --git a/src/Umbraco.Core/Services/IMemberService.cs b/src/Umbraco.Core/Services/IMemberService.cs index 1c66640cd1..6238cf05a8 100644 --- a/src/Umbraco.Core/Services/IMemberService.cs +++ b/src/Umbraco.Core/Services/IMemberService.cs @@ -24,6 +24,13 @@ namespace Umbraco.Core.Services /// IMember GetByKey(Guid id); + /// + /// Gets a member by it's id + /// + /// + /// + IMember GetById(int id); + /// /// Get all members for the member type alias /// diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs index 74e9046c15..807b250ea7 100644 --- a/src/Umbraco.Core/Services/IMembershipMemberService.cs +++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs @@ -50,7 +50,12 @@ namespace Umbraco.Core.Services /// T CreateMemberWithIdentity(string username, string email, string password, string memberTypeAlias, bool raiseEvents = true); - T GetById(int id); + /// + /// Gets the member by the provider key + /// + /// + /// + T GetByProviderKey(object id); /// /// Get a member by email diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs index 08b94380bb..d7cd655cd8 100644 --- a/src/Umbraco.Core/Services/MemberService.cs +++ b/src/Umbraco.Core/Services/MemberService.cs @@ -642,17 +642,18 @@ namespace Umbraco.Core.Services /// /// /// - 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(); + if (asGuid.Success) { return GetByKey((Guid)id); } + var asInt = id.TryConvertTo(); + if (asInt.Success) + { + return GetById((int)id); + } return null; } diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 5891c88247..96045178f0 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -140,6 +140,17 @@ namespace Umbraco.Core.Services } } + public IUser GetByProviderKey(object id) + { + var asInt = id.TryConvertTo(); + if (asInt.Success) + { + return GetById((int)id); + } + + return null; + } + public IUser GetByEmail(string email) { using (var repository = _repositoryFactory.CreateUserRepository(_uowProvider.GetUnitOfWork())) diff --git a/src/Umbraco.Tests/Services/UserServiceTests.cs b/src/Umbraco.Tests/Services/UserServiceTests.cs index 2f350b94de..17ad5a1031 100644 --- a/src/Umbraco.Tests/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests/Services/UserServiceTests.cs @@ -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] diff --git a/src/Umbraco.Web/Security/Providers/UmbracoServiceMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UmbracoServiceMembershipProvider.cs index f2e79a769b..84bd8dc65b 100644 --- a/src/Umbraco.Web/Security/Providers/UmbracoServiceMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UmbracoServiceMembershipProvider.cs @@ -346,12 +346,7 @@ namespace Umbraco.Web.Security.Providers /// 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; diff --git a/src/umbraco.businesslogic/User.cs b/src/umbraco.businesslogic/User.cs index 8eb0ec5e34..89ce9324f5 100644 --- a/src/umbraco.businesslogic/User.cs +++ b/src/umbraco.businesslogic/User.cs @@ -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 /// 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 /// 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); diff --git a/src/umbraco.cms/businesslogic/workflow/Notification.cs b/src/umbraco.cms/businesslogic/workflow/Notification.cs index 492763995e..89bac801f0 100644 --- a/src/umbraco.cms/businesslogic/workflow/Notification.cs +++ b/src/umbraco.cms/businesslogic/workflow/Notification.cs @@ -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),