Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Good way to redirect to a "members only" section of website

by ww (Archbishop)
on Feb 02, 2013 at 16:29 UTC ( [id://1016721]=note: print w/replies, xml ) Need Help??


in reply to Good way to redirect to a "members only" section of website

And "hi" back, Yagna. Welcome to the Monastery.

But I'm confused. You say "I want the user to be logged into the main webpage."

Do you mean "logged into the default page (perhaps index.html -- ie, in some vernaculars, what's called the "landing"page) for the visitor initially arriving at your site, or do you mean that a successful login puts the user on a page whereon s/he can interact with the "two page application?"

My personal preference is to have the login script redirect to the ap if the uname/pw passes your tests... and, otherwise, to have it call a second CGI script which will throw up a new page which says 'That username doesn't match that password" or similar and provides a link (emphasis, LINK; NOT a redirect>) to the default (index.html or whatever).

I'm not going to bother to offer a detailed (and perhaps even rational) explanation of that preference; it's not something I've detailed -- in my own mind; let alone on paper -- to the degree needed to make it readable and defensible (which it may or may not be)   :( .

  • Comment on Re: Good way to redirect to a "members only" section of website

Replies are listed 'Best First'.
Re^2: Good way to redirect to a "members only" section of website
by Shuraski (Scribe) on Feb 02, 2013 at 17:02 UTC

    Yagna, my best advice is to use Catalyst to get this functionality nicely.

    You include Catalyst::Plugin::Authentication just like it says in the Catalyst Tutorial.

    You basically end up leading off each templated page that you want restricted to logged-in users with this:

    [% IF c.user_exists %] ...the rest of your content here... [% END %]
    Your home page or whatever you want to call it won't include this code at the head, so users who haven't logged in yet can see the content that you've not restricted. It works nicely without a lot of fuss. Have fun!

      Hi Shuraski, Since my application is simple I wanted to stay away from frameworks. I will test it out just get a feel for using catalyst. Thanks, Yagna
Re^2: Good way to redirect to a "members only" section of website
by yagna (Novice) on Feb 02, 2013 at 17:17 UTC
    Hi WW, The default page is as you mentioned index.cgi. Sounds like the general approach is to redirect to a index.html/index.cgi on successful login. Just a clarification: the two page includes the login page (so I have the login page and an index.cgi) Thanks for confirming! Yagna

      " the two page includes the login page...."
      Actually, if I read your explanation as you intended, that's exactly what I'm urging you to avoid.

      My preferred schema is:
      1. Create a default, static "index.html (.asp. .net, whatever)" FOR EVERY VISITOR which includes a link to "login.cgi"
      2. Have login.cgi's (separate) action script (call it "login_test.cgi") check the uname and pw against whatever you're using for your "approved members" list
          ...if successful,
        call "application_page1.cgi"
          } else {
          ...call "page2.html" which announces "login failed" or similar (as in my initial reply) and provides a link to the default ("index.html" or whatever).

      You can, without dangerously deviatating from my schema, have login_test.cgi's failure action send a user who entered the wrong credentials directly back to index.html without any explanation, but that's unkind to the maker of an innocent error.

      Please excuse my assumptions about your intent; I've been known to err (but with good intent) in that area.

        Hi ww, Thanks for the clarification. I am using a model similar to the ajax login form as dettailed here Since this uses ajax, the login error message is displayed in the same page. My question is about how you "call" another cgi script? That is my problem. How on successful authentication, I redirect(call) another cgi script/ html page ?

        ...if successful, call "application_page1.cgi" } else { ...call "page2.html"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1016721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-19 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found