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 create and login userprogrammatically create and login user
Previous
 
Next
New Post
10/9/2007 7:37 AM
 

Hi,

I want to programmatically create a new DNN user and login this user if the user registration was successfully. The user creation part doesn't seem to be a problem, but I'm struggling with how to automatically/programmatically login the user I just created.

Anyone any idea? Thanks!

Thanks,

rudgr

 
New Post
10/9/2007 10:54 AM
 


Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
10/10/2007 9:53 AM
 
I also need to programmatically login and logout of DNN. My reason is that I am creating a custom Login module that logs into a separate database, but I want to allow DNN admin and host logins through the same module so the DNN login token isn't needed in the skin.

I have copied the login code from the standard DNN AuthenticationServices login and created the function 'pf_DNNLogin' below. This function correctly identifies if the user is valid or not, allows me to retrieve the user's information, and even puts an event in the DNN events if an invalid login occurs. The problem I have is that it does not update the navigation menus to have the Admin or Host options when admin or host log in, or put an event in the DNN events if a valid login occurs.

I presume I need to raise the 'OnUserAuthenticated' event somehow to tell DNN that a valid login has occurred - but I am unable to use the code in the standard DNN AuthenticationServices login as my module is a standard module and therefore inherits 'Entities.Modules.PortalModuleBase' and not 'AuthenticationLoginBase'.

So - does anybody know of any way of telling DNN that a valid login has occurred? And likewise informing DNN when the user logs out?

Private Function pf_DNNLogin() As Boolean
'
' Tries to login to DNN using txtUser.Text and txtPassword.Text
'
' Returns:
' True if the login was successful - false if not
'
Dim loginStatus As UserLoginStatus = UserLoginStatus.LOGIN_FAILURE
Dim bLoggedIn As Boolean = False
'
' Login the user
Dim objUser As UserInfo = UserController.ValidateUser(PortalId, txtUser.Text, txtPassword.Text, "DNN", "", PortalSettings.PortalName, pf_IPAddress(), loginStatus)
If Not (loginStatus = UserLoginStatus.LOGIN_USERNOTAPPROVED) Then
bLoggedIn = (loginStatus <> UserLoginStatus.LOGIN_FAILURE)
End If
'
' Return if logged in
Return bLoggedIn
End Function
 
New Post
1/7/2008 9:53 AM
 

Hi Dee,

I am having exact same problem. Have you found a solution for this?

 
New Post
1/7/2008 11:27 AM
 

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.

 


Jim www.walkspoiled.com
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0programmatically create and login userprogrammatically create and login 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