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.0Programmatically Creating  Role Groups and Roles.Programmatically Creating Role Groups and Roles.
Previous
 
Next
New Post
8/16/2007 5:39 AM
 

Hi,
I am adding new users from an uploaded excel spreadsheet and adding a Specific Role [in a Role Group] to them.

 I've written code [below ] to do this successfully, but there are a couple of outstanding [minor] issues.

1. Because there isn't a "GetRoleGroupByName" method on the DotNetNuke.Security.Roles.RoleController,
I have to iterate through the returned arraylist from "GetRoleGroups".

Can "GetRoleGroupByName" be added to the class??

2. If the RoleGroup Doesn't exist, I create it [successfully]. Problem is, the following code doesn't appear to recognise that it's there.
A check On the Admin>Security Roles Show that the group And role was created And Subsequent calls To the code are good With the user being created With the roles in the group As expected.
I suspect this is a caching issue. Any thoughts?

 

code:

          Rec_UserInfo = DotNetNuke.Entities.Users.UserController.GetUserByName(Me.PortalId, RecPMQ_Users.User_Logon)
                    If Rec_UserInfo Is Nothing Then
                        'Now, create a new DNN User for this IFA
                        Rec_UserInfo = New DotNetNuke.Entities.Users.UserInfo
                        Rec_UserInfo.FirstName = "Fred"
                        Rec_UserInfo.LastName = "Bloggs"
                        Rec_UserInfo.Username = "logob Phrase"
                        'Membership details
                        Rec_UserInfo.Membership.Password = "Password"
                        Rec_UserInfo.DisplayName = "Fred Bloggs"
                        Rec_UserInfo.Email = "FB @ Foo.com"
                        Rec_UserInfo.Membership.Approved = True
                        Rec_UserInfo.PortalID = Me.PortalId


                        Rec_UserInfo.Profile.FirstName = Rec_UserInfo.FirstName
                        Rec_UserInfo.Profile.LastName = Rec_UserInfo.LastName
                        Rec_UserInfo.Profile.Telephone = RecPMQ_Users.User_MobilePhone


                        Rec_UserInfo.IsSuperUser = False
                        Dim createStatus As DotNetNuke.Security.Membership.UserCreateStatus = DotNetNuke.Entities.Users.UserController.CreateUser(Rec_UserInfo)
                        If createStatus = DotNetNuke.Security.Membership.UserCreateStatus.Success Then
                            SuccessfulEntries += 1
                            'Add  this user to the Designated Role
                            Rec_UserInfo = DotNetNuke.Entities.Users.UserController.GetUserByName(Me.PortalId, "Logon Phrase")
                            If Rec_UserInfo Is Nothing Then
                                Me.lbl_Stage3Message.Text = "There was a problem setting up the User record in the database - Please call Administration"
                            Else
                                Dim oDate As Date = CDate("1/1/2020")
                                Dim RC As New DotNetNuke.Security.Roles.RoleController
                                'Check for RoleGroup.
                                Dim ColRoleGroups As ArrayList
                                Dim GroupId As Integer = -1
                                Dim k As Integer
                                ColRoleGroups = DotNetNuke.Security.Roles.RoleController.GetRoleGroups(PortalId)
                                For k = 0 To ColRoleGroups.Count - 1
                                    If CType(ColRoleGroups(k), DotNetNuke.Security.Roles.RoleGroupInfo).RoleGroupName = "Project Group" Then
                                        GroupId = CType(ColRoleGroups(k), DotNetNuke.Security.Roles.RoleGroupInfo).RoleGroupID
                                        Exit For
                                    End If
                                Next
                                If GroupId = -1 Then
                                    'Create new RoleGroup
                                    Dim oRoleGroup As New DotNetNuke.Security.Roles.RoleGroupInfo
                                    oRoleGroup.Description = "Project Group for Users"
                                    oRoleGroup.PortalID = PortalId
                                    oRoleGroup.RoleGroupName = "Project Group"
                                    GroupId = DotNetNuke.Security.Roles.RoleController.AddRoleGroup(oRoleGroup)
                                End If

                                Dim oRoleCheck As DotNetNuke.Security.Roles.RoleInfo
                                oRoleCheck = RC.GetRoleByName(Me.PortalId, "Manager")
                                If oRoleCheck Is Nothing Then
                                    'Create the Role.
                                    oRoleCheck = New DotNetNuke.Security.Roles.RoleInfo
                                    oRoleCheck.PortalID = PortalId
                                    oRoleCheck.RoleName = "Manager"
                                    oRoleCheck.Description = "Project Role for the Manager"
                                    oRoleCheck.ServiceFee = 0
                                    oRoleCheck.BillingPeriod = 0
                                    oRoleCheck.BillingFrequency = ""
                                    oRoleCheck.TrialFee = 0
                                    oRoleCheck.TrialPeriod = 0
                                    oRoleCheck.IsPublic = False
                                    oRoleCheck.AutoAssignment = False
                                    oRoleCheck.RoleGroupID = GroupId
                                    Dim role_ID As Integer
                                    role_ID = RC.AddRole(oRoleCheck)
                                    DotNetNuke.Common.Utilities.DataCache.RemoveCache("GetRoles")
                                End If

                                Dim oRole As DotNetNuke.Security.Roles.RoleInfo
                                oRole = RC.GetRoleByName(Me.PortalId, CType(ObjCntroller.PMQ_GetChoiceByValue(PMQ_BindTypes.Roles, CInt(params(3))), PMQ_Choices).PMQ_ChoiceDescription)
                                If Not oRole Is Nothing Then
                                    RC.AddUserRole(Me.PortalId, Rec_UserInfo.UserID, oRole.RoleID, oDate)
                                  
                                Else
                                    Me.lbl_Stage3Message.Text = "There was a problem adding the Project Role to the User - Please call Administration"
                                    Exit Sub
                                End If
                            End If

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Programmatically Creating  Role Groups and Roles.Programmatically Creating Role Groups and Roles.


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