Reputation: 4397
I've been through this tutorial which has been really helpful: http://www.blogfodder.co.uk/2011/12/31/umbraco-membership-templates
But VS is telling me that all my methods are obsolete. It tells me replacement methods to use for everything except setting the member type. Originally this was done in the Member.MakeNew method by passing MemberType as a parameter.
I've been to the Umbraco site and looked at the documentation on Membership, but there's a big note saying: "NOTE: This information is out of date and should be updated." http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-members
Does anyone know where I can find some updated code for creating members? And yes I have spent some time looking on google but all I can find is the older code.
Upvotes: 0
Views: 1491
Reputation: 577
If you are using umbraco 7 and some later versions of 6, you probably want to do this
IMember newMember = ApplicationContext.Current.Services.MemberService.CreateMember(emailAddress, emailAddress, memberName, memberTypeAlias);
or
IMember newMember = ApplicationContext.Current.Services.MemberService.CreateMemberWithIdentity(emailAddress, emailAddress, memberName, memberTypeAlias);
then
ApplicationContext.Current.Services.MemberService.Save(newMember);
to save the new member. Member must be saved before attempting to add to a group. To add to a group in umbraco 7 do
ApplicationContext.Current.Services.MemberService.AssignRole(newMember.Id, "Group Name");
Upvotes: 1
Reputation: 4397
I've managed to update my code to use .net membership without too much hassle.
Membership.CreateUser(...) replaces Member.MakeNew(...)
Roles.AddUserToRole(newMember,umbracoGroup) replaces newMember.AddGroup(umbracoGroup.Id).
But according to this post here http://our.umbraco.org/forum/developers/extending-umbraco/14614-Using-membership-provider-to-create-members-from-code, if you're using .net membership, it's only possible to have 1 MemberType by setting it in the web.config.
So hopefully I'll be able to stick to 1 MemberType, otherwise I'll be rolling my code back to use the Umbraco Membership classes.
Upvotes: 1
Reputation: 26267
Umbraco uses .net membership since 4.5, or possibly even before this.
To create a user invoke the Membership.CreateUser method
Upvotes: 1