Copied to clipboard

Flag this post as spam?

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


  • Nathan Skidmore 63 posts 251 karma points c-trib
    Feb 26, 2016 @ 11:23
    Nathan Skidmore
    0

    Umbraco Identity - how to create a member within a custom member type

    Hi,

    I am using the UmbracoIdentity package and am trying to register a member to an alternative member type. I have created the member type in Umbraco and followed the in-code comments in the 'Register' view. Therefore I have initialised the register model like so:

    var registerModel = Members.CreateRegistrationModel("MyMemberTypeAlias");
    

    However when I register the member they still get added to the 'Member' member type. Looking at the code I think this is because the UmbracoIdentityAccountController HandleRegisterMember action doesn't do anything with the model's MemberTypeAlias. The UmbracoApplicationMember doesn't appear to have any properties that I can use to assign the alternative MemberTypeAlias either.

    How can I register a member to a custom member type?

    Thanks,

    Nathan

  • Nathan Skidmore 63 posts 251 karma points c-trib
    Mar 03, 2016 @ 16:30
    Nathan Skidmore
    100

    I worked out an alternative registration process using the member service to achieve what I wanted. My register member action method now looks like this:

    [HttpPost]
    [AllowAnonymous]
    public async Task<ActionResult> HandleRegisterMember([Bind(Prefix = "registerModel")]RegisterModel model)
        {
    
            if (ModelState.IsValid == false)
            {
                return CurrentUmbracoPage();
            }
    
            var username = model.UsernameIsEmail || model.Username == null ? model.Email : model.Username;
            var memberService = Services.MemberService;
    
            if (memberService.GetByUsername(username) == null)
            {
                //register member
                var member = memberService.CreateMember(username, model.Email, model.Name, model.MemberTypeAlias);
                memberService.Save(member);
                memberService.SavePassword(member, model.Password);
    
                //authenticate member
                var user = await UserManager.FindAsync(username, model.Password);
                if (user != null)
                {
                    await SignInAsync(user, isPersistent: false);
    
                    //if there is a specified path to redirect to then use it
                    if (!model.RedirectUrl.IsNullOrWhiteSpace())
                    {
                        return Redirect(model.RedirectUrl);
                    }
    
                    //redirect to current page by default
                    return RedirectToCurrentUmbracoPage();
                }
            }
            else
            {
                //username already exists
                ModelState.AddModelError("registerModel", "The email address provided has already been registered");
            }
    
            return CurrentUmbracoPage();
        }
    
  • Shannon Deminick 1530 posts 5278 karma points MVP 3x
    Mar 07, 2016 @ 12:19
    Shannon Deminick
    0

    Hi can you please create an issue/PR for this so it can be resolved in the library? https://github.com/Shazwazza/UmbracoIdentity

  • Nathan Skidmore 63 posts 251 karma points c-trib
    Mar 07, 2016 @ 13:16
    Nathan Skidmore
    0

    No probs. I'll get on it now.

  • 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