If I want assign a membertype in .NET Code behind ( not using default membertype specified into web.config ) and using .NET Login Controls, How Do I do this?
I think that I made a custom usercontrol without .NET Login Control as in Umbraco v3.x.y.
Inherit the UmbracoMembershipProvider and override the CreateUser function. It should do the trick! Don't forget to change the provider then in web.config
It doesn't work however if you're using more than 1 provider... Unless someone else has anothers solution!
Inherit the UmbracoMembershipProvider and override the CreateUser function. It should do the trick! Don't forget to change the provider then in web.config
It doesn't work however if you're using more than 1 provider... Unless someone else has anothers solution!
Regards,
/Dirk
[/quote]
Hi, Dirk,
overriding CreateUser function, I could to pass, at runtime, to MakeNew, membertype value from usercontrol.
Maybe ab idea!
OK I think I now know what you want to achieve... Is it this?
[code]MemberType demoMemberType = new MemberType(1040); //id of membertype ‘demo’
Member newMember = Member.MakeNew(txtName.Text, demoMemberType, new umbraco.BusinessLogic.User(0));[/code]
I know that code and I'm going to use it for developping custom registration usercontrol without .NET Login controls as WizardCreateUser control.
But it's not possible use it with .NET Cretion Wizard control and choose at runtime membertype if in web.config I setup:
because WizardControl assign membertype "testmember" to every new user of every sites.
Then, I wish:
- If possible, using .NET Login CreateUserWizard Control and choose at runtime which membertype I need
- My umbraco install is for multisites so every site needs different membertype. Then defaultMemberTypeAlias in web.config is not good solution
Maybe simple "wizard" (not out of the box .NET CreateUser Wizard ) and
[code]
MemberType demoMemberType = new MemberType(1040); //id of membertype ‘demo’
Member newMember = Member.MakeNew(txtName.Text, demoMemberType, new umbraco.BusinessLogic.User(0));
[/code]
code is good solution.
Do other .NET Login Control work (recovery password, ecc ) if member is created with "makenew"?
I'm thinking of something else right now. I'm almost sure you could subscribe to the CreatedUser event and change the member's type!
I've checked the db and a 'Member''s data is saved both in cmsMember table (holding the default properties email, login and password) whereas all other member (profile) properties are stored as with any other node (cmsContentXml table). 'Member Type' property of member is saved as 'nodeTypeAlias'. Can this be an option in your case?
I'm thinking of something else right now. I'm almost sure you could subscribe to the CreatedUser event and change the member's type!
I've checked the db and a 'Member''s data is saved both in cmsMember table (holding the default properties email, login and password) whereas all other member (profile) properties are stored as with any other node (cmsContentXml table). 'Member Type' property of member is saved as 'nodeTypeAlias'. Can this be an ...
[/quote] yes, maybe. Have you an example? Thanks. Bye from Salsburg!
Hi all, I am trying to do something similar here, where I use the standard .NET membership controls. So, when I create a user I need to be able to associate them with one of many MemberType (not groups). The reason why I need this is because I have some heavy customizations in the Umbraco back office where I rely on the member type to store member data etc.
So, with Rubens suggestion below I would need to interject this during creation of the member becuase I don't see any way to access the MemberType of a member as part of the member. I was hoping to be bale to set it in the CreatedUser event, but am now thinking that I can tap into CreatingUser? Does anyone have any suggestions on this?
Forgive the fact that everything here is in VB for sample code, but that's my language of choice and familiarity.
I have abandoned the standard .NET Login and CreateUserWizard in favor of customized controls that will still allow the LoginView and LoginStatus to work properly. I am still about a week out from having something refined and fully tested, but I promise to make a package and the source code available on CodePlex in the near future.
In the most basic form, I would start with two properties on a custom control and the necessary Imports (using for you C guys).
Public WriteOnly Property MemberGroup() As String
Set(ByVal value As String)
objMemberGroup = MemberGroup.GetByName(value)
nvcMemberGroup = value
End Set
End Property
Public WriteOnly Property MemberType() As String
Set(ByVal value As String)
objMemberType = MemberType.GetByAlias(value)
nvcMemberType = value
End Set
End Property
[/code]
This provides the flexibility of changing the member group and/or type on a page by page (or template by template) need. Add the required fields for basic registration (name, email, password) and then create the member manually through code.
[code]
Private Sub RegisterClick
Dim oMember As Member
Dim oMemberHandler As New WICATech.MembershipHandlers
oMember = oMemberHandler.RegisterUser(nvcMemberGroup, nvcMemberType, rFirstName.Text, rLastName.Text, _
rEmailAddress.Text, rPassword.Text, rUsername.Text)
End Sub
[/code]
I have a function built for handling the meat and potatoes of creating the new user below. I did it this way to call this function from other places in my library as needed and return the member object for additional processing as needed.
[code]
Public Function RegisterUser(ByVal vMemberGroup As String, ByVal vMemberType As String, _
ByVal FirstName As String, ByVal LastName As String, ByVal EmailAddress As String, _
ByVal Password As String, ByVal Username As String) As Member
Dim newMemberGroup As MemberGroup = MemberGroup.GetByName(vMemberGroup)
Dim newMemberType As MemberType = MemberType.GetByAlias(vMemberType)
Dim newMember As Member = Member.MakeNew(FirstName & " " & LastName, newMemberType, New umbraco.BusinessLogic.User(0))
On the login function, again a custom login control is needed to handle the processing of the login itself. Two text boxes and a submit button are enough to get this one rolling. Note that because of what "might" be a bug in the Umbraco Membership Provider library I have implemented a "clone" of the hashing process used on passwords. (Off-topic: salting passwords might be a good idea in a future release for enhanced security).
Again we start off with some Imports and public properties:
[code]
Imports umbraco.cms.businesslogic.member
Imports umbraco.providers
Public WriteOnly Property MemberGroup() As String
Set(ByVal value As String)
objMemberGroup = MemberGroup.GetByName(value)
nvcMemberGroup = value
End Set
End Property
Public WriteOnly Property MemberType() As String
Set(ByVal value As String)
objMemberType = MemberType.GetByAlias(value)
nvcMemberType = value
End Set
End Property
[/code]
And then a login function to call when the button is clicked:
[code]
Public Sub LoginClick()
If Login(tUsername.Text, tPassword.Text, objMemberGroup) = True Then
'Do something to login in the user
Else
' Do something to tell user they failed login
End if
End Sub
Public Function Login(ByVal Username As String, ByVal Password As String, _
ByVal objMemberGroup As MemberGroup) As Boolean
Dim oSecurity As New SecurityHandlers
Dim oMember As Member = Member.GetMemberFromLoginNameAndPassword(Username, _
oSecurity.EncryptPassword(Password))
Dim mProvider As New umbraco.providers.UsersMembershipProvider
If Not IsNothing(oMember) Then
' check against the membership group
Dim hshGroups As Hashtable = oMember.Groups
Dim enumerator As IDictionaryEnumerator = hshGroups.GetEnumerator
While enumerator.MoveNext
Dim hshMemberGroup As MemberGroup = enumerator.Value
If hshMemberGroup.Id = objMemberGroup.Id Then
' log in
Member.AddMemberToCache(oMember)
Return True
Else
' login failed
Return False
End If
End While
Else
' login failed
Return False
End If
Return False
End Function
[/code]
The custom password hashing feature for circumstances when "hashed" is the password mechanism:
[code]
Public Function EncryptPassword(ByVal Password As String) As String
Dim hash As System.Security.Cryptography.HMACSHA1 = New System.Security.Cryptography.HMACSHA1
hash.Key = Encoding.Unicode.GetBytes(Password)
EncryptPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(Password)))
End Function
[/code]
I actually ended up sticking with .NET controls and using Macro paramaters to pass in the Applicable membership provider via that. So, my code looks a little something like:
CrateUserWizard1.MembershipType=_membershipType;
And in web.config I set the various membership types default value to the appropriate one. I had to leave the defaultMembershipProvider poitnign to the Umbraco one in orde to kepp existing Umbraco specific functionality though.
Umbraco v4: Membership and .NET
( continue from http://forum.umbraco.org/yafpostst5335V4-Membership-Provider-and-ASPNET-controls.aspx ... )
Hi,
my question is:
If I want assign a membertype in .NET Code behind ( not using default membertype specified into web.config ) and using .NET Login Controls, How Do I do this?
I think that I made a custom usercontrol without .NET Login Control as in Umbraco v3.x.y.
Bye
Hi Iq_p118,
Inherit the UmbracoMembershipProvider and override the CreateUser function. It should do the trick! Don't forget to change the provider then in web.config
It doesn't work however if you're using more than 1 provider... Unless someone else has anothers solution!
Regards,
/Dirk
Hi,
I did a blog post with an example on how to integrate multiple providers if that is what you need.
Cheers,
Ruben
[quote=Dirk]Hi Iq_p118,
Inherit the UmbracoMembershipProvider and override the CreateUser function. It should do the trick! Don't forget to change the provider then in web.config
It doesn't work however if you're using more than 1 provider... Unless someone else has anothers solution!
Regards,
/Dirk
[/quote]
Hi, Dirk,
overriding CreateUser function, I could to pass, at runtime, to MakeNew, membertype value from usercontrol.
Maybe ab idea!
Bye
[quote=Ruben]Hi,
I did a blog post with an example on how to integrate multiple providers if that is what you need.
Cheers,
Ruben[/quote]
Thanks, for you reply Ruben,
but I haven't an external auth server.
I want to use Umbraco Member + ASP.NET Login Control with the possibility to choose, a runtime, membertype.
:-k
What exactly is the "membertype" going to do? To me, it sounds like a member group, which is implemented. Is that what you need?
[quote=Ruben]What exactly is the "membertype" going to do? To me, it sounds like a member group, which is implemented. Is that what you need?[/quote]
But in MemberGroup is not possible to specify proprierties as Umbraco MemberType.
OK I think I now know what you want to achieve... Is it this?
[code]MemberType demoMemberType = new MemberType(1040); //id of membertype ‘demo’
Member newMember = Member.MakeNew(txtName.Text, demoMemberType, new umbraco.BusinessLogic.User(0));[/code]
Hi,
I know that code and I'm going to use it for developping custom registration usercontrol without .NET Login controls as WizardCreateUser control.
But it's not possible use it with .NET Cretion Wizard control and choose at runtime membertype if in web.config I setup:
because WizardControl assign membertype "testmember" to every new user of every sites.
Then, I wish:
- If possible, using .NET Login CreateUserWizard Control and choose at runtime which membertype I need
- My umbraco install is for multisites so every site needs different membertype. Then defaultMemberTypeAlias in web.config is not good solution
Maybe simple "wizard" (not out of the box .NET CreateUser Wizard ) and
[code]
MemberType demoMemberType = new MemberType(1040); //id of membertype ‘demo’
Member newMember = Member.MakeNew(txtName.Text, demoMemberType, new umbraco.BusinessLogic.User(0));
[/code]
code is good solution.
Do other .NET Login Control work (recovery password, ecc ) if member is created with "makenew"?
Thanks
Hi Iq_p118,
I'm thinking of something else right now. I'm almost sure you could subscribe to the CreatedUser event and change the member's type!
I've checked the db and a 'Member''s data is saved both in cmsMember table (holding the default properties email, login and password) whereas all other member (profile) properties are stored as with any other node (cmsContentXml table). 'Member Type' property of member is saved as 'nodeTypeAlias'. Can this be an option in your case?
Regards,
/Dirk
[quote=Dirk]Hi Iq_p118,
I'm thinking of something else right now. I'm almost sure you could subscribe to the CreatedUser event and change the member's type!
I've checked the db and a 'Member''s data is saved both in cmsMember table (holding the default properties email, login and password) whereas all other member (profile) properties are stored as with any other node (cmsContentXml table). 'Member Type' property of member is saved as 'nodeTypeAlias'. Can this be an ...
[/quote] yes, maybe. Have you an example? Thanks. Bye from Salsburg!
I returned from that beautyfull city.
Have you some news?
I'm going to create an usercontrol without ASP.NET Membership...
Hi all, I am trying to do something similar here, where I use the standard .NET membership controls. So, when I create a user I need to be able to associate them with one of many MemberType (not groups). The reason why I need this is because I have some heavy customizations in the Umbraco back office where I rely on the member type to store member data etc.
So, with Rubens suggestion below I would need to interject this during creation of the member becuase I don't see any way to access the MemberType of a member as part of the member. I was hoping to be bale to set it in the CreatedUser event, but am now thinking that I can tap into CreatingUser? Does anyone have any suggestions on this?
THanks,
Nik
Forgive the fact that everything here is in VB for sample code, but that's my language of choice and familiarity.
I have abandoned the standard .NET Login and CreateUserWizard in favor of customized controls that will still allow the LoginView and LoginStatus to work properly. I am still about a week out from having something refined and fully tested, but I promise to make a package and the source code available on CodePlex in the near future.
In the most basic form, I would start with two properties on a custom control and the necessary Imports (using for you C guys).
[code]
Imports umbraco.providers
Imports umbraco.cms.businesslogic.member
Public WriteOnly Property MemberGroup() As String
Set(ByVal value As String)
objMemberGroup = MemberGroup.GetByName(value)
nvcMemberGroup = value
End Set
End Property
Public WriteOnly Property MemberType() As String
Set(ByVal value As String)
objMemberType = MemberType.GetByAlias(value)
nvcMemberType = value
End Set
End Property
[/code]
This provides the flexibility of changing the member group and/or type on a page by page (or template by template) need. Add the required fields for basic registration (name, email, password) and then create the member manually through code.
[code]
Private Sub RegisterClick
Dim oMember As Member
Dim oMemberHandler As New WICATech.MembershipHandlers
oMember = oMemberHandler.RegisterUser(nvcMemberGroup, nvcMemberType, rFirstName.Text, rLastName.Text, _
rEmailAddress.Text, rPassword.Text, rUsername.Text)
End Sub
[/code]
I have a function built for handling the meat and potatoes of creating the new user below. I did it this way to call this function from other places in my library as needed and return the member object for additional processing as needed.
[code]
Public Function RegisterUser(ByVal vMemberGroup As String, ByVal vMemberType As String, _
ByVal FirstName As String, ByVal LastName As String, ByVal EmailAddress As String, _
ByVal Password As String, ByVal Username As String) As Member
Dim newMemberGroup As MemberGroup = MemberGroup.GetByName(vMemberGroup)
Dim newMemberType As MemberType = MemberType.GetByAlias(vMemberType)
Dim newMember As Member = Member.MakeNew(FirstName & " " & LastName, newMemberType, New umbraco.BusinessLogic.User(0))
newMember.Email = EmailAddress
newMember.Password = Password
newMember.LoginName = Username
newMember.XmlGenerate(New System.Xml.XmlDocument)
newMember.Save()
newMember.AddGroup(newMemberGroup.Id)
Return newMember
End Function
[/code]
On the login function, again a custom login control is needed to handle the processing of the login itself. Two text boxes and a submit button are enough to get this one rolling. Note that because of what "might" be a bug in the Umbraco Membership Provider library I have implemented a "clone" of the hashing process used on passwords. (Off-topic: salting passwords might be a good idea in a future release for enhanced security).
Again we start off with some Imports and public properties:
[code]
Imports umbraco.cms.businesslogic.member
Imports umbraco.providers
Public WriteOnly Property MemberGroup() As String
Set(ByVal value As String)
objMemberGroup = MemberGroup.GetByName(value)
nvcMemberGroup = value
End Set
End Property
Public WriteOnly Property MemberType() As String
Set(ByVal value As String)
objMemberType = MemberType.GetByAlias(value)
nvcMemberType = value
End Set
End Property
[/code]
And then a login function to call when the button is clicked:
[code]
Public Sub LoginClick()
If Login(tUsername.Text, tPassword.Text, objMemberGroup) = True Then
'Do something to login in the user
Else
' Do something to tell user they failed login
End if
End Sub
Public Function Login(ByVal Username As String, ByVal Password As String, _
ByVal objMemberGroup As MemberGroup) As Boolean
Dim oSecurity As New SecurityHandlers
Dim oMember As Member = Member.GetMemberFromLoginNameAndPassword(Username, _
oSecurity.EncryptPassword(Password))
Dim mProvider As New umbraco.providers.UsersMembershipProvider
If Not IsNothing(oMember) Then
' check against the membership group
Dim hshGroups As Hashtable = oMember.Groups
Dim enumerator As IDictionaryEnumerator = hshGroups.GetEnumerator
While enumerator.MoveNext
Dim hshMemberGroup As MemberGroup = enumerator.Value
If hshMemberGroup.Id = objMemberGroup.Id Then
' log in
Member.AddMemberToCache(oMember)
Return True
Else
' login failed
Return False
End If
End While
Else
' login failed
Return False
End If
Return False
End Function
[/code]
The custom password hashing feature for circumstances when "hashed" is the password mechanism:
[code]
Public Function EncryptPassword(ByVal Password As String) As String
Dim hash As System.Security.Cryptography.HMACSHA1 = New System.Security.Cryptography.HMACSHA1
hash.Key = Encoding.Unicode.GetBytes(Password)
EncryptPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(Password)))
End Function
[/code]
Hi wicatech,
thanks for sharing your methods. I think it may be smart to do this outside of the CreateUserWizard and other standard .NET controls now.
Thanks for your input.
-- Nik
I agree....
I actually ended up sticking with .NET controls and using Macro paramaters to pass in the Applicable membership provider via that. So, my code looks a little something like:
And in web.config I set the various membership types default value to the appropriate one. I had to leave the defaultMembershipProvider poitnign to the Umbraco one in orde to kepp existing Umbraco specific functionality though.
HTH's some one else as well.
Cheers,
Nik
is working on a reply...