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

HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Can you force a login from a module?Can you force a login from a module?
Previous
 
Next
New Post
9/1/2011 4:54 PM
 
I created a new page and added the Account Login to it and then modified the Site Settings to use that page as my Login page. Now the code works like a charm!!! Thanks again for all your help!
 
New Post
9/2/2011 1:04 PM
 
Steven Webster wrote:
Arlene, a few options:

1. Use DNN page level security to restrict to registered users (on the page your module will be shown on) and let DNN handle the login redirect for non authenticated users.

2. Do the same on your module level settings...but you won't get the redirect...it just won't show to non authenticated users but you can display a message to unauthenticated users telling them to login or just show the login.

3. You can check for a userid in code and if it's -1 the user is not logged in.  You can then build a redirect to the login page and even include the return url info.

Something along these line would do it

if (UserId == -1)
            {
                PortalSettings MyPortalSettings = PortalController.GetCurrentPortalSettings();
                Response.Redirect(Globals.NavigateURL(MyPortalSettings.LoginTabId));
            }


Yes you can create your own login.   I don't have any code examples handy but it's doable....just look at the source for the core login.

I would be interested in #1. 

The only way I have been able to allow a user to see a page and then have DNN redirect non-authenticated user to a login page is to:

  • create two pages with the same name 
  • have the first page in the menu and allow access to everyone 
  • have the first page link to the second page
  • have the second page for authenticated users only .

I there an easier way?

Thanks,
Greg Hart

 
New Post
9/2/2011 1:45 PM
 
I've managed to get my module to redirect to a login page when I need the user to login but I'm still working on getting it to return to page it came from afterwards.

To get it to redirect you do the following:
  1. create a new page in DNN and place the Account Login module on it
  2. go to the Site Settings for the site and under Advanced Settings there is a drop down for the Login Page - select the new page that you added.
  3. In my module, which is in VB, I added an Import statement:
    Imports DotNetNuke.Entities.Users
  4. In my subroutine I added the following variable:
    Dim MyPortalSettings As PortalSettings = PortalController.GetCurrentPortalSettings()
  5. Also in my subrouting I added the following code for the redirect:
    If UserInfo.UserID = -1 Then
         Response.Redirect(Globals.NavigateURL(MyPortalSettings.LoginTabId))
    End If
My code now redirects to my custom login page with no problems.  The problem I am now trying to solve how to get the login page to redirect back to my modules page once a user has logged in.  The first response to this forum entry indicated that I should be able to pass a return url to the custom login page.  I haven't found out how to do this yet but I'm working on it.

As far as #1 is concerned - you can set a page to require a login by going to the Admin --> Pages link.  Highlight the page and then edit it. Under Permissions make sure that there is no check mark next to 'All Users' and check off 'Registered Users' in the View Page column.  That will result in the page not showing in the navigation until a user logs onto the site.

Hope that helps.  If I find more info about the redirect back to the original page I will post it.
 
New Post
9/2/2011 2:25 PM
 
I found a better solution. See the following blog entry.

http://www.dotnetnuke.com/Resources/Forums/forumid/-1/postid/218921/scope/posts.aspx

I made a subroutine from the code associated with this response, called it 'ForceLogin()', removed my custom login page from the site and I call the subroutine when I need to have the user log in. Works very nicely.
 
New Post
9/8/2011 11:39 AM
 
Arlene, nice work and glad you've figured it all out.

Greg, Yes, you can set permissions on the modules as well. As an example create a single page and place two HTML modules on it. Go to setting for each. Set one to Anonymous (uncheck inherit and make sure all users is unchecked) and set the other to registered member.

Add content to each that's different enough to recognize like"

"Hey, you're note logged in" and "Welcome Member!"

No access that page when not logged in and when logged in.

The possibilities are pretty endless for showing not only pages, but content on pages to specific roles. We do a lot of that as it keeps the page maintenance and content states all organized on a single page.



Steven Webster
Manager, Community Platform
F5 Networks, DevCentral
 
Previous
 
Next
HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Can you force a login from a module?Can you force a login from a module?


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