Here is some code cloned from the DNN forms provider that appears to work to log a user in.
Private Sub LetsLogUserIn(ByVal objUserInfo As UserInfo, ByVal ExternalUserinfo As ExternalUser)
Try
'Lets log the user in
Dim loginStatus As DotNetNuke.Security.Membership.UserLoginStatus
System.Web.HttpContext.Current.Trace.Write( _
"Login check dnn user: current/checking " & _
Entities.Users.UserController.GetCurrentUserInfo.UserID & _
"/" & objUserInfo.UserID)
If Entities.Users.UserController.GetCurrentUserInfo.UserID <> objUserInfo.UserID Then
System.Web.HttpContext.Current.Trace.Write("User Not logged in Let s do it for " & objUserInfo.Username)
ExternalRoutines.logDNNMessage("User Check: ", "Logging In User " & objUserInfo.Username)
''First Validate them - this did not work!!! and nulled out the user object....
'objUserInfo = _
' UserController.ValidateUser(ExternalUserinfo.PortalID, _
' objUserInfo.Username, objUserInfo.Username, "", _
' ExternalUserinfo.PortalName, _
' System.Web.HttpContext.Current.Request.UserHostAddress, _
' loginStatus)
System.Web.HttpContext.Current.Trace.Write("Signing them out")
FormsAuthentication.SignOut()
System.Web.HttpContext.Current.Response.Cookies("portalaliasid").Value = Nothing
System.Web.HttpContext.Current.Response.Cookies("portalaliasid").Path = "/"
System.Web.HttpContext.Current.Response.Cookies("portalaliasid").Expires = _
DateTime.Now.AddYears(-30)
System.Web.HttpContext.Current.Response.Cookies("portalroles").Value = Nothing
System.Web.HttpContext.Current.Response.Cookies("portalroles").Path = "/"
System.Web.HttpContext.Current.Response.Cookies("portalroles").Expires = _
DateTime.Now.AddYears(-30)
Localization.SetLanguage( _
DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings. _
DefaultLanguage)
System.Web.HttpContext.Current.Trace.Write("Log them in - INFO coming....")
System.Web.HttpContext.Current.Trace.Write("Log them in user/potal/pid " & _
"/" & ExternalUserinfo.PortalName & "/" & ExternalUserinfo.PortalID)
Entities.Users.UserController.UserLogin(ExternalUserinfo.PortalID, _
objUserInfo, _
ExternalUserinfo.PortalName, _
System.Web.HttpContext.Current.Request.UserHostAddress, _
True)
System.Web.HttpContext.Current.Trace.Write("Logged in completed")
'Send them around again - to ensure login completed...
'System.Web.HttpContext.Current.Response.Redirect( _
' System.Web.HttpContext.Current.Request.Url. _
' OriginalString, True)
End If
Catch ex As Exception
DotNetNuke.Services.Exceptions.LogException(ex)
ExternalRoutines.logDNNMessage("LetsLogUserIn Error:", ex.InnerException.Message)
End Try
End Sub
A companion routine is used to create the user in the DNN database based upon credentials from another database.
Private Sub check_dnn_user(ByRef objUserInfo As UserInfo, ByRef ExternalUserinfo As ExternalUser)
Try
SWH.Current.Trace.Write("Entering Check DNN User - First Name/Portal/PId:" & ExternalUserinfo.FirstName & _
"/" & ExternalUserinfo.PortalName & "/" & ExternalUserinfo.PortalID)
Dim objUserCreateStatus As DotNetNuke.Security.Membership.UserCreateStatus
'See if user exists in DNN Portal user DB
objUserInfo = Entities.Users.UserController.GetUserByName( _
ExternalUserinfo.PortalID, _
ExternalUserinfo.FirstName & "_" & ExternalUserinfo.LastName)
' user does exist - try to create on the fly
If objUserInfo Is Nothing Then
SWH.Current.Trace.Write("Need to Create User")
objUserInfo = New UserInfo
objUserInfo.DisplayName = ExternalUserinfo.FirstName & "_" & ExternalUserinfo.LastName
objUserInfo.FirstName = ExternalUserinfo.FirstName
objUserInfo.LastName = ExternalUserinfo.LastName
objUserInfo.Username = ExternalUserinfo.FirstName & "_" & ExternalUserinfo.LastName
objUserInfo.Membership.Password = "trytogusessit123456"
objUserInfo.PortalID = ExternalUserinfo.PortalID
objUserInfo.Email = ExternalUserinfo.FirstName & "_" & ExternalUserinfo.LastName & "@test.com"
objUserCreateStatus = Entities.Users.UserController.CreateUser(objUserInfo)
If objUserCreateStatus = DotNetNuke.Security.Membership.UserCreateStatus.Success Then
ExternalRoutines.logDNNMessage("User Check: ", "Created User " & _FirstName & "_" & _LastName)
SWH.Current.Trace.Write("Created User")
Else
SWH.Current.Trace.Write("FAILED to Create User")
ExternalRoutines.logDNNMessage("User Check: ", _
"Error Creating User: " & _FirstName & "_" & _LastName & " " & _
objUserCreateStatus)
_LastName = "not logged on"
objUserInfo = Nothing
End If
End If
SWH.Current.Trace.Write("leaving check dnn user for " & objUserInfo.DisplayName)
Catch ex As Exception
DotNetNuke.Services.Exceptions.LogException(ex)
_LastName = "No Logged in"
ExternalRoutines.logDNNMessage("Check DNN User: ", _
"Failed to Find/Create User:" & _FirstName & "_" & _LastName)
End Try
End Sub
Once you have DNN users created in this fashion, you can add other DNN roles or make them an admin or super user.