Hi,
I've been trying to test your example in my DNN 4.5.3 local install but I'm not able to create a user. There must be something I'm missing. Below is my code if anyone would be so kind as to point me in the right direction.
Thanks in advance.
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Entities.Modules.Actions
Imports DotNetNuke.Entities.Profile
Imports DotNetNuke.Security.Profile
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Mail
Imports DotNetNuke.Security.Membership
Imports DotNetNuke.UI.Skins.Controls.ModuleMessage
Imports DotNetNuke.UI.Utilities
Imports DotNetNuke.UI.WebControls
Namespace MyNameSpace
Partial Class ManageUsers
Inherits UserModuleBase
Implements IActionable
#Region "Event Handlers"
' Page_Load runs when the control is loaded
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strUsername, strFirstName, strLastName, strEmailAddress As String
Dim blnMembershipApproved As Boolean
strUsername = Request.QueryString("e")
strFirstName = Request.QueryString("fn")
strLastName = Request.QueryString("ln")
strEmailAddress = Request.QueryString("e")
blnMembershipApproved = True
Try
CreateNewUser(strUsername, strFirstName, strLastName, strEmailAddress, blnMembershipApproved)
Catch ex As Exception 'Module failed to load
ProcessModuleLoadException(Me, ex)
End Try
End Sub
Public Function CreateNewUser(ByVal strUsername As String, ByVal strFirstName As String, ByVal strLastName As String, _
ByVal strEmailAddress As String, ByVal blnMembershipApproved As Boolean) As DotNetNuke.Security.Membership.UserCreateStatus
'===============================================================================
'
' BEGIN VALIDATION
'
'===============================================================================
' preliminary check to be sure that the fields are filled in
' (cannot have empty values)
If String.IsNullOrEmpty(strUsername) Then _
Throw New NullReferenceException("The USERNAME variable for CreateNewUser() cannot be empty.")
If String.IsNullOrEmpty(strFirstName) Then _
Throw New NullReferenceException("The FIRSTNAME variable for CreateNewUser() cannot be empty.")
If String.IsNullOrEmpty(strLastName) Then _
Throw New NullReferenceException("The LASTNAME variable for CreateNewUser() cannot be empty.")
If String.IsNullOrEmpty(strEmailAddress) Then _
Throw New NullReferenceException("The EMAILADDRESS variable for CreateNewUser() cannot be empty.")
' validate the e-mail address format
'If Not MyNameSpace.Common.Utilities.RegExLibrary.ValidateEmailFormat(strEmailAddress) Then _
' Throw New Exception("The e-mail address was in an invalid format")
'===============================================================================
'
' END VALIDATION
'
'===============================================================================
' create a new user instance and populate it
Me.User = New DotNetNuke.Entities.Users.UserInfo
With Me.User
.Profile.InitialiseProfile(PortalSettings.PortalId)
.AffiliateID = -1
.DisplayName = String.Concat(strFirstName, " ", strLastName)
.Email = strEmailAddress
.FirstName = strFirstName
.IsSuperUser = False
.Membership.Approved = blnMembershipApproved
.Membership.CreatedDate = DateTime.Now
.Membership.Email = strEmailAddress
.Membership.Password = DotNetNuke.Entities.Users.UserController.GeneratePassword
'.Membership.Password = MyNameSpace.Security.PasswordGenerator.Generate(8, 10)
.Membership.UpdatePassword = True
.Membership.Username = strUsername
.PortalID = PortalSettings.PortalId
.Username = strUsername
.Profile.FirstName = strFirstName
.Profile.LastName = strLastName
.Profile.PreferredLocale = Me.PortalSettings.DefaultLanguage
.Profile.TimeZone = Me.PortalSettings.TimeZoneOffset
End With
' I am now handling this in the customized profile/membership provider(s)
' Set the Approved status based on the Portal Settings
'If Me.PortalSettings.UserRegistration = DotNetNuke.Common.Globals.PortalRegistrationType.PublicRegistration Then
'Me.User.Membership.Approved = True
'Else
' Me.User.Membership.Approved = False
'End If
' attempt to create the DNN user
Dim objStatus As UserCreateStatus = DotNetNuke.Entities.Users.UserController.CreateUser(Me.User)
' set-up the arguments for the status of the user creation
Dim e As DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs
If objStatus = UserCreateStatus.Success Then
e = New DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs(Me.User)
e.Notify = True
Response.Write(" objStatus = UserCreateStatus.Success ")
Else ' registration error
e = New DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs(Nothing)
e.Notify = False
Response.Write("NOT objStatus = UserCreateStatus.Success ")
End If
e.CreateStatus = objStatus
' perform some DNN logic
Me.UserCreateCompleted(e)
Return objStatus
End Function
Private Sub UserCreateCompleted(ByVal e As UserUserControlBase.UserCreatedEventArgs)
Dim strMessage As String = ""
Try
If e.CreateStatus = UserCreateStatus.Success Then
Dim objUser As UserInfo = e.NewUser
'If IsRegister Then
' send notification to portal administrator of new user registration
'Mail.SendMail(User, MessageType.UserRegistrationAdmin, PortalSettings)
Else
'If e.Notify Then
' 'Send Notification to User
' If PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
' Mail.SendMail(User, MessageType.UserRegistrationVerified, PortalSettings)
' Else
'Mail.SendMail(User, MessageType.UserRegistrationPublic, PortalSettings)
'End If
' End If
End If
'Else
'End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
#Region "Optional Interfaces"
''' -----------------------------------------------------------------------------
''' <summary>
''' Gets the ModuleActions for this ModuleControl
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [cnurse] 3/01/2006 created
''' </history>
''' -----------------------------------------------------------------------------
Public ReadOnly Property ModuleActions() As ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
Get
Dim Actions As New ModuleActionCollection
If (IsAdminTab Or IsHostTab) And (Me.ModuleId > -1) Then
If Not AddUser Then
Actions.Add(GetNextActionID, Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "add.gif", EditUrl(), False, SecurityAccessLevel.Admin, True, False)
If ProfileProviderConfig.CanEditProviderProperties Then
Actions.Add(GetNextActionID, Localization.GetString("ManageProfile.Action", LocalResourceFile), ModuleActionType.AddContent, "", "icon_profile_16px.gif", EditUrl("ManageProfile"), False, SecurityAccessLevel.Admin, True, False)
End If
End If
'Actions.Add(GetNextActionID, Localization.GetString("Cancel.Action", LocalResourceFile), ModuleActionType.AddContent, "", "lt.gif", ReturnUrl, False, SecurityAccessLevel.Admin, True, False)
End If
Return Actions
End Get
End Property
#End Region
End Class
End Namespace