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?
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.
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!
Creating Members with .net controls
I am having no luck getting the following code to work:
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?
Hi Bob,
Can you maybe post the error you are getting? This will help searching in the right direction :-)
Cheers,
Michael.
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?
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.
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
is working on a reply...