I use a base class which can check the appropriate permissions/credentials in the
cgiapp_prerun phase. Here's an example where I check to see if a user has an admin bit -- all the administration modules in this app inherit from this. If the user doesn't have the right credentials, then the runmode is reset to
unauthorized, which just displays a "permission denied" screen. You can use the same technique for interrupting the session with a login screen -- although for this app I use
mod_auth_tkt for that purpose instead.
package Alex2::CGI::Admin;
use strict;
use warnings;
use base 'Alex2::CGI';
sub setup {
my $self = shift;
$self->run_modes( [ 'main' ] );
$self->start_mode( 'main' );
}
sub cgiapp_prerun {
my $self = shift;
$self->SUPER::cgiapp_prerun( @_ );
$self->run_modes( [ 'unauthorized' ] );
unless( $self->user->admin or $self->user->group_admin ) {
$self->prerun_mode( 'unauthorized' );
}
# group admins can only use certain tools
if ( $self->user->group_admin and !$self->allows_group_admin ) {
$self->prerun_mode( 'unauthorized' );
}
}
....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.