Copied to clipboard

Flag this post as spam?

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


  • Bob Jones 33 posts 54 karma points
    Jan 04, 2012 @ 12:51
    Bob Jones
    0

    Creating Members with .net controls

    I am having no luck getting the following code to work:

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) {
                // after the user has been created, we need to pull up the member object...
                Member registeredMember = Member.GetMemberFromLoginName(CreateUserWizard1.UserName);
    
                // try to save the entire profile with all the data that we filled in...
                if (registeredMember != null && registeredMember.Id > 0) {
                    try {
                        //Member profile update based on info found in registration wizard
                        MemberProfileUpdate(registeredMember);
                    } catch {
                        Log.Add(LogTypes.Custom, User.GetUser(0), Node.GetCurrent().Id,
                                        new StringBuilder().Append("Error while persisting member profile info for member '").Append(registeredMember.Text).Append("' (").Append(registeredMember.Id).Append(")!").ToString());
                    }
                }
    
                // do NOT login the user after the registration as we need to get some money first...
                CreateUserWizard1.LoginCreatedUser = false;
            }
    
    
            // Method takes all of our Web form data and associates it with out member record
            private void MemberProfileUpdate(Member member) {
                //Get profile info from regsitration wizard (form data)
                TextBox userNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
    
    
                // set the member properties (defined in Umbraco Members section)...
                member.getProperty("UserName").Value = userNameTextBox.Text;
    
                //E-mail is set to username as e-mail is used as username
                member.Email = member.LoginName;
    
                //Set user friendly name for member node in admin backend
                if (!string.IsNullOrEmpty(userNameTextBox.Text))
                    member.Text = userNameTextBox.Text;
    
                // add member to a group that we've specified (in this case passed in via macro param)
                MemberGroup addToMemberGroup = MemberGroup.GetByName("Standard");
                member.AddGroup(addToMemberGroup.Id);
                member.ContentType = MemberType.GetByAlias("SiteMember");
                // save the Umbraco member (persist to DB)
                member.Save();
            }

    I am trying to use this with a CreateUserWizard .net control and for some infuriating reason the debugger will not work with this code so I cannot work out where the problem is coming from. Can someone explain the best practices for a creating members and a general login/logout functions?

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 04, 2012 @ 13:45
    Michael Latouche
    0

    Hi Bob,

    Can you maybe post the error you are getting? This will help searching in the right direction :-)

    Cheers,

    Michael.

  • Bob Jones 33 posts 54 karma points
    Jan 04, 2012 @ 13:52
    Bob Jones
    1

    Sorry bit of a mistake on my part. I was mistaking the code that I was using with code to create a user, not realising that the CreateUserWizard literally does all of that for me. The error was coming from the web config and changing the default member type to one that has been created. The only line of code I really need (for now at least) in the CreatedUser event of the control is one to add the role.

     

    Sorry, can I delete my question?

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 04, 2012 @ 14:01
    Michael Latouche
    0

    Hi Bob,

    Yes, the "default member type" error is quite common ;-) It's good that you got it sorted out!!

    As far as deleting the question is concerned, you cannot do that yourself but, who knows, if an admin comes on this thread, he might delete it then...

    Cheers,

    Michael.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 04, 2012 @ 14:19
    Dirk De Grave
    1

    Why would you want to delete the post/question. It's more helpful to others who may have the same problem as you've experienced, after all, this is what makes this forum so strong!

     

    Cheers, and a big h5yr for providing feedback!

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft