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.
- 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.
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:
So far my new code looks like:
Which I believe would create the new user with a username, password. What I'm not sure on is how to:
Would be greatful if someone could point me in the right direction.
Thanks in advance,
Eddie
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
Hi Tom
The posts http://www.aaron-powell.com/umbraco-members-profiles and http://umbraco.miketaylor.eu/2010/08/29/authenticating-new-members/ are just what I needed.
Thanks,
Eddie
is working on a reply...