I have had some research, merge all reference code and developed a working script for you.
You have to still do some modification in my script as your requirement. My script developed for add users programmatically in DNN website. I think you need to do foreach
loop to insert all your Google users from XML file. You can do it to call Dim status As UserCreateStatus = CreateUser(Me.PortalId)
line in foreach
loop.
Step 1: Create role "Google User" in your DNN website.
Step 2: Create member variable of MembershipProvider
in your class.
Private Shared memberProvider As DotNetNuke.Security.Membership.MembershipProvider = DotNetNuke.Security.Membership.MembershipProvider.Instance()
Step 3: Set your XML user data in below method.
Private Shared Function GetUserInfo(ByVal fiPortalId As Integer) As UserInfo
Dim a As New UserInfo
a.FirstName = FirstName
a.LastName = LastName
a.PortalID = fiPortalId
a.Email = EMail
a.Username = UserName
a.DisplayName = DisplayName
Dim objMembership As UserMembership = New UserMembership
objMembership.Approved = True
objMembership.CreatedDate = DateTime.Now
objMembership.Email = EMail
objMembership.Username = UserName
objMembership.Password = Password
a.Membership = objMembership
a.IsSuperUser = False
Return a
End Function
Step 4: Create user method.
Public Shared Function CreateUser(ByVal fiPortalId As Integer) As UserCreateStatus
Dim createStatus As UserCreateStatus = UserCreateStatus.AddUser
Dim user As UserInfo = GetUserInfo(fiPortalId)
'Create the User
createStatus = memberProvider.CreateUser(user)
If createStatus = UserCreateStatus.Success Then
'Dim objEventLog As New Services.Log.EventLog.EventLogController
'objEventLog.AddLog(objUser, PortalController.GetCurrentPortalSettings, UserController.GetCurrentUserInfo.UserID, "", Services.Log.EventLog.EventLogController.EventLogType.USER_CREATED)
DataCache.ClearPortalCache(user.PortalID, False)
addRoleToUser(user, "Google User", DateTime.Now.AddYears(25))
End If
Return createStatus
End Function
Step 5: Apply role to all users.
Public Shared Function addRoleToUser(ByRef user As UserInfo, ByVal roleName As String, ByRef expiry As DateTime) As Boolean
Dim rc As Boolean = False
Dim roleCtl As RoleController = New RoleController
Dim newRole As RoleInfo = roleCtl.GetRoleByName(user.PortalID, roleName)
If newRole IsNot Nothing And user IsNot Nothing Then
roleCtl.AddUserRole(user.PortalID, user.UserID, newRole.RoleID, DateTime.MinValue, expiry)
user = UserController.GetUserById(user.PortalID, user.UserID)
rc = user.IsInRole(roleName)
End If
Return rc
End Function
I had test above script in my computer and it works. Please let me know if you have any questions.