Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Dec 30, 2011 @ 00:03
    Eddie Foreman
    0

    Create new member using Membership CreateUser

    Hi All,

    I have a registration form, were upon submisson a new member is created in Umbraco.  Previoulsy I used Member.MakeNew which looks like it's now obsolete.

    Previously my code was:

    Member m = Member.MakeNew(string.Format("{0} {1}", name.Text.Trim(), surname.Text.Trim()), email.Text, membertype, new umbraco.BusinessLogic.User(0));
    m.LoginName = email.Text;
    m.Password = Membership.GeneratePassword(7, 1);
    MemberGroup mg = MemberGroup.GetByName("Registered");
    m.AddGroup(mg.Id);
    m.XmlGenerate(new System.Xml.XmlDocument());
    m.Save();

    So far my new code looks like:

    MembershipUser m = Membership.CreateUser(string.Format("{0} {1}", name.Text.Trim(), surname.Text.Trim()), Membership.GeneratePassword(7,1));
    Roles.AddUserToRole(m.LoginName, "Registered")

    Which I believe would create the new user with a username, password.  What I'm not sure on is how to:

    • Assign the user a member type
    • Give the user a Login Name - different to username
    • Assign the user to a group - Think it should be - Roles.AddUserToRole(msu.UserName, "Registered")   - but would like to use Login Name instead of msu.Username
    • Create the XML and save the new user

    Would be greatful if someone could point me in the right direction.

    Thanks in advance,
    Eddie

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 30, 2011 @ 14:24
    Tom Fulton
    0

    Hi Eddie,

    Not an expert on the subject, but here are my thoughts:

    - The Member Type is determined by a setting in the web.config, see Dirk's post here:  http://our.umbraco.org/forum/developers/api-questions/21440-Members,-MemberTypes-and-Roles

    - I think Username & Login Name are actually the same thing in the .NET membership provider.  I think if you want to store their actual "name" you would do so in a custom property.

    - I don't think it's necessary to generate the XML manually.

    Note I typically use the CreateUserWizard which handles a lot for you.   There's a good blog post about this here:  http://umbraco.miketaylor.eu/2010/08/29/authenticating-new-members/

    Also if you need to use custom properties I would suggest using this method, it works really well:  http://www.aaron-powell.com/umbraco-members-profiles

    Hope this helps,
    Tom

  • Eddie Foreman 215 posts 288 karma points
    Dec 30, 2011 @ 21:24
  • 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