Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
I think you've got your design backwards. You're trying to go to the home page first. Generally, the steps are:
  1. User goes to the website.
  2. User is presented with a login page.
  3. User enters credentials (username/password, generally).
  4. User hits submit.
  5. Server validates credentials
    1. If invalid, server re-sends login page with useful-ish error message
    2. If valid, server sends home page. Server also sets cookie to indicate user has logged in successfully
  6. All other pages check for existence of cookie. If cookie isn't there, redirect to login page.

This means that your cookie-checking method is in the base class. Your pages are in the child classes. cgiapp_prerun() will call your cookie-checking method to determine if it should redirect to the login page or not. The runmode method won't even be executed unless the cookie is there and has been verified.

Generally, one has one C::A child to do logging in, logging out, password changes, etc. Then, you have a few other C::A children that do actual content generation. So, you'd actually have two CGI scripts - one for login and one for show_survey. Both would inherit from your baseclass.

We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

In reply to Re: Structuring multiple CGI::Application modules II by dragonchild
in thread Structuring multiple CGI::Application modules II by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.