I'm writing some code in which I want to create a member. The problem is I don't know what is the best way to create a member. You can use Member.MakeNew or System.Web.Security.Membership.CreateUser. In CreateUser the UmbracoMembershipProvider is called which uses the following code:
///
<summary>
/// Adds a new membership user to the data source.
///</summary>
///<param name="username">The user name for the new user.</param>
///<param name="password">The password for the new user.</param>
///<param name="email">The e-mail address for the new user.</param>
///<param name="passwordQuestion">The password question for the new user.</param>
///<param name="passwordAnswer">The password answer for the new user</param>
///<param name="isApproved">Whether or not the new user is approved to be validated.</param>
///<param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
///<param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"></see> enumeration value indicating whether the user was created successfully.</param>
///<returns>
/// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the information for the newly created user.
Now this code still creates an Umbraco Member using Member.MakeNew, but you can't choose your member type for instance. It uses m_DefaultMemberTypeAlias which is set using the following code:
// test for membertype (if not specified, choose the first member type available)
if (config["defaultMemberTypeAlias"] != null)
m_DefaultMemberTypeAlias = config[
"defaultMemberTypeAlias"];
elseif (MemberType.GetAll.Length == 1)
m_DefaultMemberTypeAlias =
MemberType.GetAll[0].Alias;
else
thrownewProviderException("No default MemberType alias is specified in the web.config string. Please add a 'defaultMemberTypeAlias' to the add element in the provider declaration in web.config");
Since I'd like to have the option to choose the MemberType I guess using Member.MakeNew is the best option, but on the wiki it says the member class will be obsoleted in Umbraco 4.1. What should I do?
You should go with the membership api's instead of the member api. Create your own membership provider, probably inheriting from the umbraco membership provider implementation and override the CreateUser() method, so you'd have the option to choose whatever member type you'd like instead of the current 'hard-coded' choice.
Hey Dirk that sounds like a good solution! Will the UmbracoMembershipProvider be more flexible in Umbraco 4.1? If it's going to be the new standard you should at least have the option to choose your own MemberType.
I tried to create my own MembershipProvider which inherits from UmbracoMembershipProvider, but it's not as easy as I was hoping. Since almost everything in the UmbracoMembershipProvider is private I can't use most of the code I need. For instance in my own CreateUser method I also need to convert an Umbraco Member to an asp.net MembershipUser. There is a nice method called ConvertToMembershipUser which can do this, but it's private so I can't use it. Also a lot of private strings which I need can't be accessed. This way it's almost impossible to create my own MembershipProvider. Guess for now I'm going to use the old Umbraco Member class until this is fixed.
Use Member Or UmbracoMembershipProvider
Hello,
I'm writing some code in which I want to create a member. The problem is I don't know what is the best way to create a member. You can use Member.MakeNew or System.Web.Security.Membership.CreateUser. In CreateUser the UmbracoMembershipProvider is called which uses the following code:
Now this code still creates an Umbraco Member using Member.MakeNew, but you can't choose your member type for instance. It uses m_DefaultMemberTypeAlias which is set using the following code:
Since I'd like to have the option to choose the MemberType I guess using Member.MakeNew is the best option, but on the wiki it says the member class will be obsoleted in Umbraco 4.1. What should I do?
The code was a lot more readable in the editor.... This forum still needs some fixing.....
You should go with the membership api's instead of the member api. Create your own membership provider, probably inheriting from the umbraco membership provider implementation and override the CreateUser() method, so you'd have the option to choose whatever member type you'd like instead of the current 'hard-coded' choice.
Does that sound as an option to you?
Cheers,
/Dirk
Hey Dirk that sounds like a good solution! Will the UmbracoMembershipProvider be more flexible in Umbraco 4.1? If it's going to be the new standard you should at least have the option to choose your own MemberType.
I'd suggest that as a new feature on Codeplex. No promises it will make it into the core, but at least it's logged and can be voted for.
Cheers,
/Dirk
I created a workitem on codeplex. You can find it here: http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=25808. It's reported as an issue though.... Couldn't find how to change the type to feature.
I tried to create my own MembershipProvider which inherits from UmbracoMembershipProvider, but it's not as easy as I was hoping. Since almost everything in the UmbracoMembershipProvider is private I can't use most of the code I need. For instance in my own CreateUser method I also need to convert an Umbraco Member to an asp.net MembershipUser. There is a nice method called ConvertToMembershipUser which can do this, but it's private so I can't use it. Also a lot of private strings which I need can't be accessed. This way it's almost impossible to create my own MembershipProvider. Guess for now I'm going to use the old Umbraco Member class until this is fixed.
I also created a workitem for this on codeplex: http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=25855
is working on a reply...