How to customize DNN's user account module
2/03/2008
One of the things that has delayed the release of my website is the register form. In my opinion the official module requests too much information from the user. I believe that just a login, email and password should be mandatory.
Unfortunately this module is not that flexible and can't be configured this way. If you want to change it you'll have to get to the source.
So I did.
1) First you have to download the DotNetNuke sources. I've customized them both with 4.07.00 and 4.08.00
2) You'll have to modify two files DotNetNuke_04.08.00_Source\Library\Components\Users\UserInfo.vb
and
DotNetNuke_04.08.00_Source\Library\Components\Users\Profile\ProfileController.vb
3) Hide the unneeded fields from the register form. Modify the DisplayName, FirstName, LastName, UserId and Username properties in UserInfo.vb as follows.
<Browsable(False)> Public Property DisplayName() As String
Get
Return _DisplayName
End Get
Set(ByVal Value As String)
_DisplayName = Value
End Set
End Property
<SortOrder(1), MaxLength(256), Required(True), _
RegularExpressionValidator(glbEmailRegEx)> _
Public Property Email() As String
Get
Return _Email
End Get
Set(ByVal Value As String)
_Email = Value
\'Continue to set the membership Property in case developers have used this
\'in their own code
Me.Membership.Email = Value
End Set
End Property
<Browsable(False)> Public Property FirstName() As String
Get
Return Profile.FirstName
End Get
Set(ByVal Value As String)
Profile.FirstName = Value
End Set
End Property
<Browsable(False)> Public Property LastName() As String
Get
Return Profile.LastName
End Get
Set(ByVal Value As String)
Profile.LastName = Value
End Set
End Property
<Browsable(False)> Public Property UserID() As Integer
Get
Return _UserID
End Get
Set(ByVal Value As Integer)
_UserID = Value
End Set
End Property
<SortOrder(0), IsReadOnly(True), Required(True)> Public Property Username() As String
Get
Return _Username
End Get
Set(ByVal Value As String)
_Username = Value
\' Set the First Name, Last Name and Display Name\'
Profile.FirstName = Value
Profile.LastName = Value
_DisplayName = Value
\'Continue to set the membership Property in case developers have used this
\'in their own code
Me.Membership.Username = Value
End Set
End Property
4) In the previous step we're preventing the first name and last name from being written to the database. Now we want dnn to stop complaining about an incomplete profile when we log in to the portal. Modify the UpdateUserProfile method in ProfileController.vb as follows
Public Shared Function UpdateUserProfile(ByVal objUser As UserInfo, ByVal profileProperties As ProfilePropertyDefinitionCollection) As UserInfo5) Finally you'll have to compile the library and upload DotNetNuke.dll to your DNN installation. After that the register module will only ask for a username, email and password.
Dim updateUser As Boolean = Null.NullBoolean
'Iterate through the Definitions
For Each propertyDefinition As ProfilePropertyDefinition In profileProperties
Dim propertyName As String = propertyDefinition.PropertyName
Dim propertyValue As String = propertyDefinition.PropertyValue
If propertyDefinition.IsDirty Then
'Update Profile
objUser.Profile.SetProfileProperty(propertyName, propertyValue)
'If propertyName.ToLower = "firstname" OrElse propertyName.ToLower = "lastname" Then
' updateUser = True
'End If
End If
Next
UpdateUserProfile(objUser)
If updateUser Then
UserController.UpdateUser(objUser.PortalID, objUser)
End If
Return objUser
End Function
Etiquetas: customize, DNN, dotnetnuke, user account module