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

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...create user and assign to role programmaticallycreate user and assign to role programmatically
Previous
 
Next
New Post
1/20/2007 2:41 PM
 

I'm looking at how to take data from a form submission by user A, and based upon content of that form, create two new users, assign each to a role, and generate a preformatted email with unique data added to the email body which is then sent to each user.

The scenario is that they are required and authorized to add certain kinds of information regarding the person who submitted the initial form.

Included in the email would be their newly generated userid, password, instructions on what info they need to provide, and a link back to a page in the portal which would present to them a form already tied to the previous form. I anticipate using querystring to accomplish the latter.

There are a few discrete pieces of this. I guess at this point I'm most interested in how to create a new user and attach to a role programmatically. I want to be sure to replicate DNN practices, leverage DNN's sprocs as possible to make sure that all the necessary tables get populated correctly.

Anyone done something like this and familiar with the code and any issues?


pmgerholdt
 
New Post
1/20/2007 9:08 PM
 

I have done exactly this.  Theres a lot of code but youll see what I did

        Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
            If AddUser Then
                If IsValid Then
                    Dim createStatus As UserCreateStatus = CreateUser()
                    AddUserToRoles(createStatus)
                    UserCreateCompleted(createStatus)
                End If
            Else
                If ((UserEditor.IsValid) Or (ProfileProperties.IsValid)) AndAlso (Not User Is Nothing) Then
                    User.Membership.UpdatePassword = False
                    UserController.UpdateUser(PortalId, User)
                End If
                AddUserToRoles()
            End If

        End Sub

IsValid is copied straight from the DNN core code.  Adduser is a DNN property.

I then used CreateUser

        Public Function CreateUser() As UserCreateStatus

            User.Membership.Approved = False

            If User.Profile.LastName = Null.NullString Then
                User.Profile.LastName = User.LastName
            End If
            If User.Profile.FirstName = Null.NullString Then
                User.Profile.FirstName = User.FirstName
            End If
            User.Profile.SetProfileProperty("AFLTeam", ddlSportTeams.SelectedItem.Text)

            Return UserController.CreateUser(User)

        End Function

 

Then

 

        Private Sub UserCreateCompleted(ByVal CreateStatus As UserCreateStatus)
            Dim strMessage As String = ""

            Try
                If CreateStatus = UserCreateStatus.Success Then

'Do what you need here

 

And I have a new routine to add the roles to users wher I have a grid of services they can click a checkbox on.

 

       Private Sub AddUserToRoles()
            Dim objRoles As New RoleController

            Dim Selected As System.Web.UI.WebControls.CheckBox
            Dim intRow As Integer
            Dim DI As DataGridItem
            Dim TC As TableCell
            Dim RoleId As Integer

            For intRow = 0 To grdServices.Items.Count - 1
                DI = grdServices.Items.Item(intRow)
                TC = DI.Cells(0)
                Selected = TC.FindControl("chkService")
                If Selected.Checked = True Then
                    RoleId = CInt(DI.Cells(1).Text)
                    Dim objRole As RoleInfo = objRoles.GetRole(RoleId, PortalSettings.PortalId)
                    If objRole.IsPublic And objRole.ServiceFee = 0.0 Then
                        objRoles.UpdateUserRole(PortalId, User.UserID, RoleId, False)
                    End If
                Else
                    RoleId = CInt(DI.Cells(1).Text)
                    Dim objRole As RoleInfo = objRoles.GetUserRole(PortalId, User.UserID, RoleId)
                    If Not objRole Is Nothing Then
                        objRoles.DeleteUserRole(PortalId, User.UserID, RoleId)
                    End If
                End If
            Next
        End Sub

 

Uses all DNN objects and no custom SQL at all. :)  Works great too.

 


Philip Beadle - Employee
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...create user and assign to role programmaticallycreate user and assign to role programmatically


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