Copied to clipboard

Flag this post as spam?

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


  • Desley 44 posts 169 karma points
    Mar 24, 2014 @ 15:46
    Desley
    0

    Member Registration

    Hello everyone,

    I find most information on the net about Umbraco is outdated so I am back here again.

    I am trying to make a standard registration form. I got everything set up besides the actual controller code.

    This is what I tried but no success:

    public class MemberRegistrationSurfaceController : Umbraco.Web.Mvc.SurfaceController
        {
            [HttpPost]
            [ActionName("Register")]
            public ActionResult MemberCreation()
            {
                    MemberType demoMemberType = new MemberType(1040);
                    Member newMember = Member.MakeNew("test", demoMemberType, new umbraco.BusinessLogic.User(0));
    
                    newMember.Email = "[email protected]";
                    newMember.Password = "test";
                    newMember.LoginName = "test";
    
                    newMember.Save();
            }
        }
    

    These methods are most likely outdated and 'obsolete' as Visual Studio always likes to tell me.

    As always, help will be greatly appreciated!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 24, 2014 @ 17:14
    Sebastiaan Janssen
    100

    This is correct (we've implemented new methods to use which are much nicer but they're only available in the upcoming version).

    Below the Save() you might want to add newMember.XmlGenerate(new XmlDocument()); although I'm not sure that's necessary just to create the member (could be though, I can't fully remember).

    If that doesn't help then the obvious next question is: what does "no success" mean? Errors? Does it not create the member at all? Or is there a problem with the created member?

    Tip: don't hardcode the member type Id, but use it's alias instead:

    var demoMemberType = MemberType.GetByAlias("myMemberTypeAlias");
    
  • Desley 44 posts 169 karma points
    Mar 25, 2014 @ 09:35
    Desley
    0

    Little brainfart. It had an incorrect MemberType ID.

    It works fine with:

    public class MemberRegistrationSurfaceController : Umbraco.Web.Mvc.SurfaceController
        {
            [HttpPost]
            [ActionName("Register")]
            public ActionResult MemberCreation()
            {
                    var demoMemberType = MemberType.GetByAlias("Member");
                    Member newMember = Member.MakeNew("test", demoMemberType, new umbraco.BusinessLogic.User(0));
    
                    newMember.Email = "[email protected]";
                    newMember.Password = "test";
                    newMember.LoginName = "test";
    
                    newMember.Save();
            }
        }
    

    Thanks for the help.

Please Sign in or register to post replies

Write your reply to:

Draft