U4-5456 - Cannot access all properties of member via MembershipHelper methods

Created by Asbjørn Riis-Knudsen 09 Sep 2014, 15:23:47 Updated by James South 18 Jun 2015, 14:05:03

Using the new MembershipHelper, I cannot access all properties of a member. This includes things like the user name, e-mail address and other special member properties, which aren't presented as normal Umbraco properties. The querying methods on MembershipHelper return members as IPublishedContent. This means that you cannot access any special member properties. Debugging the code, I can see that the value is really returned as MemberPublishedContent, which does have all the special properties. This class, however, is internal, so I cannot cast the IPublishedCcontent to it. The only alternative is to call AsDynamic(), and then access the properties using dynamics. This works, but this breaks static typing.

Comments

Sebastiaan Janssen 09 Sep 2014, 15:31:00

Huh? Please provide a code example. There's no reason member.GetPropertyValue<string>("myProperty") shouldn't work... is there?


Sebastiaan Janssen 09 Sep 2014, 15:33:41

Example:

var member = Umbraco.TypedMember(1234); var avatar = member.GetPropertyValue("avatar"); var linkedContent = member.GetPropertyValue("linkedContentPicker");


Asbjørn Riis-Knudsen 09 Sep 2014, 15:38:11

Yes, custom properties work. But I'm talking about Umbraco's built-in properties. Like the user name. I'm rendering out a list of members. Each member has a member card with a number. This number is their user name which is used to log in. The user name is not stored as a normal Umbraco property, thus it cannot be accessed via GetPropertyValue() I should be able to do this: var member = Members.GetById(item.MemberId); string membernumber = member.UserName;

That won't work, as IPublishedContent has no UserName property.

The full list of properties which cannot be accessed can be found in MemberPublishedContent.cs:

#region Membership provider member properties public string Email { get { return _membershipUser.Email; } } public string UserName { get { return _membershipUser.Username; } } public string PasswordQuestion { get { return _membershipUser.PasswordQuestion; } } public string Comments { get { return _membershipUser.Comments; } } public bool IsApproved { get { return _membershipUser.IsApproved; } } public bool IsLockedOut { get { return _membershipUser.IsLockedOut; } } public DateTime LastLockoutDate { get { return _membershipUser.LastLockoutDate; } } public DateTime CreationDate { get { return _membershipUser.CreateDate; } } public DateTime LastLoginDate { get { return _membershipUser.LastLoginDate; } } public DateTime LastActivityDate { get { return _membershipUser.LastLoginDate; } } public DateTime LastPasswordChangedDate { get { return _membershipUser.LastPasswordChangeDate; } } #endregion


Sebastiaan Janssen 09 Sep 2014, 15:47:48

Aah I see! The best I can do for you at the moment is: var pm = Members.GetCurrentMemberProfileModel();

This has the properties you need, not sure if there's another way and if not, why this is the only way. @Shandem ?


Asbjørn Riis-Knudsen 09 Sep 2014, 15:58:46

But that won't work. That gets me the profile of the currently logged-in member. I need to get this information for a random list of members IDs.

Couldn't you create an IPublishedMemberContent interface, which implements IPublishedContent and then make the methods return that instead? That would, I think, allow access to these properties, while still maintaining all the benefits of returning members as IPublishedContent. Then again, there may very well be something I'm overlooking here.


Sebastiaan Janssen 09 Sep 2014, 17:15:22

You're right, I can't find that either. You can work around it by using the Member Service but obviously that goes to the database so that's not very performant. Currently I would try and have a look in the Examine index if the information is there (not sure) but I'd like a better helper method somewhere in the Members helper to be able to access this information. Maybe I've missed something but I'll let Shannon have a look at that.


Asbjørn Riis-Knudsen 09 Sep 2014, 17:34:57

As mentioned above, my workaround at the moment is to do this: var member = Members.GetById(item.MemberId); string membernumber = member.AsDynamic().UserName;


Shannon Deminick 02 Oct 2014, 10:52:26

It's worth noting that all properties except for Email and UserName are accessible since they are actually real properties. The alias names are found in:

Constants.Conventions.Member.Comments
Constants.Conventions.Member.FailedPasswordAttempts Constants.Conventions.Member.IsApproved Constants.Conventions.Member.IsLockedOut Constants.Conventions.Member.LastLockoutDate Constants.Conventions.Member.LastLoginDate Constants.Conventions.Member.LastPasswordChangeDate Constants.Conventions.Member.PasswordAnswer Constants.Conventions.Member.PasswordQuestion


Shannon Deminick 02 Oct 2014, 10:53:41

Moving forward you'll be able to do: GetPropertyValue("Email") and GetPropertyValue("UserName")


Asbjørn Riis-Knudsen 02 Oct 2014, 10:56:09

Thanks. That was my initial expectation, so that's great!


Shannon Deminick 02 Oct 2014, 11:01:06

Fixed in: d2592bd79f94e48ccfa9b23b6f474e42b5e48e5f

I've also made MemberPublishedContent public so you can cast to it if you want as well.


Asbjørn Riis-Knudsen 24 Oct 2014, 20:17:06

Sorry to bring this up again, but shouldn't "Email" and "UserName" be added to Constants.Conventions.Member? Just so all the possible aliases are in one place - though these two are pretty self-explanatory.


James South 18 Jun 2015, 12:44:13

I was struggling with this recently with v7.2.4. I couldn't access the property {{IsApproved}} in the saved event despite using the constant.


Shannon Deminick 18 Jun 2015, 12:46:36

So are you still struggling with this or have you got it solved?


James South 18 Jun 2015, 14:05:03

Actually, ignore me. Double checking it seems to work. I think I got myself confused with how the methods on IRememberBeingDirty were calculated.


Priority: Major

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.1.0, 6.2.0, 7.1.1, 7.1.2, 7.1.3, 6.2.1, 7.1.4, 7.1.5, 6.2.2, 7.1.6

Due in version: 7.2.0

Sprint:

Story Points:

Cycle: