Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^8: RFC: Proposed tutorial - simple login script using CGI::Application

by scorpio17 (Canon)
on Jan 21, 2016 at 17:01 UTC ( [id://1153303] : note . print w/replies, xml ) Need Help??

in reply to Re^7: RFC: Proposed tutorial - simple login script using CGI::Application
in thread RFC: Proposed tutorial - simple login script using CGI::Application

It's important that all your pages be CGI::Application 'runmodes', and if you think about it in object-oriented programming terms, all of your runmodes should be methods of objects derived from some abstract base class that is itself derived from CGI::Application. Your base class contains the login logic. That way all derived classes inherit that functionality. If you redirect to some random CGI script that isn't derived from that base class, then you're right - you just bypassed your login logic. Fortunately, all you probably need to do is add:
use base 'MyLib::Login';
to your vpage.cgi script.

Replies are listed 'Best First'.
Re^9: RFC: Proposed tutorial - simple login script using CGI::Application
by Anonymous Monk on Jan 21, 2016 at 19:16 UTC
    Thank you! Let me try this...
      Hi, Unfortunately it doesn’t works and behaves same manner, it there any way to create the index.html page without HTML template (i'm looking for CGI) I have seen the some webpage like ‘http://localhost/cgi-bin/web/login’ and once success logged in the page moving to different page eg(http://localhost/cgi-bin/web/search/text) and once logged out the page automatically redirect to original login page, however after logout when trying to access to (http://localhost/cgi-bin/web/search/text) its forced to redirect to default login page - could you please suggest on this, Many Thanks.

        Probably the easiest way to make your vpage.cgi script password protected is to create a new runmode (to do this by modifying the demo, you would add a new sub in the file, use either 'private' or 'private2' as examples for this. Copy the guts of your original script into the body of this new run mode. You'll also need to create a template file to work with HTML template, for the output.

        An alternative (maybe a bit more complicated), is to modify your original script so that it is a package (like my file, but you might call this one - name doesn't matter. It will look something like this:

        package MyLib::VPage; use strict; use lib '/var/www/cgi-bin/WebApp/libs'; use base 'MyLib::Login'; sub cgiapp_init { my $self = shift; $self->SUPER::cgiapp_init; $self->authen->protected_runmodes( 'myrunmode', ); } sub myrunmode: StartRunmode { my $self = shift; my $template = $self->load_tmpl("myrunmode.html"); ### guts of old vpage.cgi go in here $template->param({ OUPUT => $output; # your output goes in here... }); return $template->output; } 1;
        To invoke this, you'll need an app file like this:
        #!/usr/bin/perl use strict; use lib '/var/www/cgi-bin/WebApp/libs'; use MyLib::VPage; my $webapp = MyLib::VPage->new( PARAMS => { cfg_file => ['simple.ini', 'vpage.ini'], format => 'equal', }, ); $webapp->run();
        The "use base MyLib::Login" line in makes VPage inherit the login logic. The vpage.ini file is optional - use it if you need to define parameters for the new run mode (or else, lump them into simple.ini).

        I hope that helps. Good luck.