Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0HOW TO: Programmatically Create New UserHOW TO: Programmatically Create New User
Previous
 
Next
New Post
6/8/2007 2:29 PM
 

And YES we are using that obviex password generator. We needed it back in 2005 and it just stayed in the app even after we've moved on to 4.5+ version.

Honestly, I find that DNN random password (I don't mean the code - didn't even look at it since I already have something, right?) to be a little too much for a regular user to look at :) - I mean all the special characters... I think alphanumeric with mixed capitalization is just fine. At least until the first login.


Vitaly Kozadayev
Principal
Viva Portals, L.L.C.
 
New Post
6/11/2007 7:55 AM
 

vitkoz wrote

And YES we are using that obviex password generator. We needed it back in 2005 and it just stayed in the app even after we've moved on to 4.5+ version.

Honestly, I find that DNN random password (I don't mean the code - didn't even look at it since I already have something, right?) to be a little too much for a regular user to look at :) - I mean all the special characters... I think alphanumeric with mixed capitalization is just fine. At least until the first login.

I agree with your assessment of the password generator.  The generated password is not at all even close to being user-friendly for the average Internet "surfer".  And a quick browse through the source didn't immediately show me a way to customize it the same way you can for most of the other configurable settings (whitespace filter, url rewrite, etc.).

In reference to your other posts, that puts me back on the drawing board for the other issue.  :)  Thanks!


Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
6/11/2007 11:04 AM
 

Hahaha!!!  Let's revert to Occam's Razor for a moment...

We all (me first) overlooked the most important thing in this user creation process.  I was passing in the portal ID, but I was not properly appending it to the UserInfo properties...  I know how I overlooked it...  I saw the "PortalID" reference in the Profile initialization line and made an incorrect assumption while proofing the code.  I didn't put the "PortalID" into the UserInfo.PortalID property of the UserInfo object.

Once I changed that, everything is working as expected with profile properties being created, the user being created and my custom code being properly called and executed. 

Whew!!!  That was a doozy...  Sorry to waste everyone's time.  :)

Here is the updated code for anyone that might want or need to use it (tested for DNN v 4.05.01 through v4.05.03):

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 = Users.UserController.CreateUser(Me.User)
     ' set-up the arguments for the status of the user creation
     Dim args As Modules.UserUserControlBase.UserCreatedEventArgs
     If objStatus = UserCreateStatus.Success Then
          args = New Modules.UserUserControlBase.UserCreatedEventArgs(Me.User)
          args.Notify = True
     Else    ' registration error
          args = New Modules.UserUserControlBase.UserCreatedEventArgs(Nothing)
          args.Notify = False
     End If
     args.CreateStatus = objStatus
     ' perform some DNN logic
     Me.UserCreateCompleted(args)
     Return objStatus
End Function 

Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
6/11/2007 1:16 PM
 

Wow... one of those things where no matter how hard you scrutinize it, your eyes just glaze past the problem and don't take notice to it.  I was wracking my brain trying to figure this out for you and don't know if I ever would have noticed that.  Glad you were able to resolve the issue!

As far as password generation goes, this link (http://www.codeproject.com/dotnet/CryptoPasswordGenerator.asp) contains details to what I have been using and it is configurable enough to make some "easy" passwords.  If you perform a "password generator" search there on the codeproject, you'll find several different methods of varying strength.  Give it a whirl.


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
7/9/2007 3:08 AM
 

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

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0HOW TO: Programmatically Create New UserHOW TO: Programmatically Create New User


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out