'umbraco.cms.businesslogic.member.Member' is obsolete: '"Use the MemberService and the Umbraco.Core.Models.Member models instead"'
Which is all good and stuff, but the MemberService (via ApplicationContext.Services.MemberService) doesn't seem to have a method to get the curretn member.
But having to provide the identity name like this makes me wonder why there isn't just a GetCurrentMember() method on the member service? Was it omitted for a reason? It was obviously there on the now obsolete old Member object...
It seems the Umbraco gods are not in my favor. The MemberService is apparently not meant for this purpose and instead I'm supposed to use the MembershipHelper (in Razor or SurfaceControllers available via the Members property)
This is all great, but does anyone know how to get to the Member properties using the MembershipHelper? For instance, when using the Members.GetCurrentMember() method as is suggested I get an IPublishedContent object.
This object obviously does not have properties for UserName, Email, IsApproved, etc. Looking at the Umbraco sources I notice that the actual type returned by the GetCurrentMember() method is MemberPublishedContent WHICH IS INTERNAL.... AARRGHHH...
So to determine whether or not the currently logged in user has comments set I need to do something like this:
var theMember = Members.GetCurrentMember();
var theRealMember = ApplicationContext.Current.Services.MemberService.GetById(theMember.Id);
var theComments = theRealMember.Comments;
Getting the same user twice just because they're different types does not seem at all logical to me. Does anyone know if I'm missing something completely (or why there are multiple ways to get members that return completely different and incompatible types)?
I've been using the Umbraco.Web.Security.MembershipHelper
var membershipHelper = new MembershipHelper(UmbracoContext);
var memberId = membershipHelper.GetCurrentMemberId();
var member = ApplicationContext.Current.Services.MemberService.GetById(memberId);
@robert - I agree, it seems like there should be a better way.
It's also worth noting that I closed the PR from @robert because the PR was using the IMemberService to check the currently logged in member. So it's true that in that case
The MemberService is apparently not meant for this purpose
But if you want to query member data that's in the db then you can of course use IMemberService - though you'd generally only want to do that in a controller since you don't want to be exposing back office data to the front-end.
If you want to know the status of the current member and work with the current members' data then the MembershipHelper is what you need to use. If you are working with the data on the front-end/razor you'll probably want to work with IPublishedContent and the MembershipHelper is what you want.
Memberservice
I'm trying to get the currently logged in Member, but when I use the GetCurrentMember() method of the Member class:
Visual Studio points out that:
Which is all good and stuff, but the MemberService (via ApplicationContext.Services.MemberService) doesn't seem to have a method to get the curretn member.
So... now what? Do I really need to
What version of Umbraco are you using? :)
I'm currently using version 7.1.4
Do you only need to get the current member to view some data or also change it. Otherwise you could use this:
You can get the id by getting the current identity.
Jeroen
Yeah, that's kind of my point. It's pretty easy to just say:
But having to provide the identity name like this makes me wonder why there isn't just a GetCurrentMember() method on the member service? Was it omitted for a reason? It was obviously there on the now obsolete old Member object...
I'm not really sure why it's missing. Maybe create an issue for it here: http://issues.umbraco.org/issues#newissue=yes
Jeroen
Added the PR https://github.com/umbraco/Umbraco-CMS/pull/494
For now I'll just use a utils function to do it I suppose. Thanks anyway.
It seems the Umbraco gods are not in my favor. The MemberService is apparently not meant for this purpose and instead I'm supposed to use the MembershipHelper (in Razor or SurfaceControllers available via the Members property)
This is all great, but does anyone know how to get to the Member properties using the MembershipHelper? For instance, when using the Members.GetCurrentMember() method as is suggested I get an IPublishedContent object.
This object obviously does not have properties for UserName, Email, IsApproved, etc. Looking at the Umbraco sources I notice that the actual type returned by the GetCurrentMember() method is MemberPublishedContent WHICH IS INTERNAL.... AARRGHHH...
So to determine whether or not the currently logged in user has comments set I need to do something like this:
Getting the same user twice just because they're different types does not seem at all logical to me. Does anyone know if I'm missing something completely (or why there are multiple ways to get members that return completely different and incompatible types)?
I've been using the Umbraco.Web.Security.MembershipHelper
@robert - I agree, it seems like there should be a better way.
The issue is logged here:
http://issues.umbraco.org/issue/U4-5456
Should be fixed up in final release of 7.2, I'll update the priority to 'major'
Thanks Shannon, I'll wait for 7.2 then :)
As Asbjørn mentions though, you can access them all dynamically:
The properties you can access are:
UserName, Email, Comments, PasswordQuestion, IsApproved, IsLockedOut, LastLockoutDate, CreationDate, LastLoginDate, LastActivityDate, LastPasswordChangedDate
It's also worth noting that I closed the PR from @robert because the PR was using the IMemberService to check the currently logged in member. So it's true that in that case
But if you want to query member data that's in the db then you can of course use IMemberService - though you'd generally only want to do that in a controller since you don't want to be exposing back office data to the front-end.
If you want to know the status of the current member and work with the current members' data then the MembershipHelper is what you need to use. If you are working with the data on the front-end/razor you'll probably want to work with IPublishedContent and the MembershipHelper is what you want.
Anyways, that's all fixed, the details are at the bottom: http://issues.umbraco.org/issue/U4-5456
is working on a reply...