Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Euge 23 posts 130 karma points
    Jun 23, 2016 @ 10:00
    Euge
    0

    Add custom property to Membership member

    Hi

    I need to programmatically add a custom property an umbraco member using the standard membership provider. I'm using Umbraco 7.3.

    So I create the member below (is this correct?) then I need to add a custom property that will store simply a list of integers.

    What approach do I take?

                var userToSave = _umbracoHelper.MembershipHelper.CreateRegistrationModel();
                userToSave.Name = "test;
                userToSave.Email = "[email protected]";
                userToSave.Password = "xxxxxxxxxxxx";
                userToSave.UsernameIsEmail = true;
                Members.RegisterMember(userToSave, out status, true);
    
  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Jun 23, 2016 @ 10:19
    Dennis Aaen
    1

    Hi Euge,

    Try to see our documentation about the member service, there you have the create method and others.

    https://our.umbraco.org/documentation/reference/management/services/memberservice

    Or in this video on Umbraco TV

    https://umbraco.tv/videos/umbraco-v7/developer/fundamentals/member-api/

    Hope this helps,

    /Dennis

  • Euge 23 posts 130 karma points
    Jun 23, 2016 @ 10:25
    Euge
    0

    Great thanks Dennis

    There doesn't appear to be anything on adding a custom property but I am thinking along the lines of

    var userToSave = _umbracoHelper.MembershipHelper.CreateRegistrationModel();
            userToSave.Name = "test;
            userToSave.Email = "[email protected]";
            userToSave.Password = "xxxxxxxxxxxx";
            userToSave.UsernameIsEmail = true;
           // add custom property here?  
          userToSave.MemberProperties.Add(.....
    
  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Jun 23, 2016 @ 12:29
    Dennis Aaen
    1

    Hi Euge,

    This video should show you have to set custom property values on a member using the Member API

    http://umbraco.tv/videos/umbraco-v7/developer/fundamentals/member-api/populating-property-values/

    Hope this helps,

    /Dennis

  • Micha Somers 134 posts 596 karma points
    Jun 23, 2016 @ 19:52
    Micha Somers
    2

    Hi Euge,

    When you have a custom member type defined in Umbraco with some extra properties (eg. a property named customMemberInformation), the following code can be used (for example in your own SurfaceController):

    ...

            MembershipCreateStatus status;
            var member = Members.RegisterMember(model, out status, model.LoginOnSuccess);
    
            // Handle custom fields
            var memberService = Services.MemberService;
            var customMember = memberService.GetByEmail(member.Email);
            customMember.SetValue("customMemberInformation", "My custom member information");
            memberService.Save(customMember);
    

    ...

    In this simplified example I store the text "My custom member information" in the custom field and save the data using the MemberService.

    Does this help you move ahead?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies