Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: CGI::Application::Authentication and Static Pages

by techcode (Hermit)
on Jan 20, 2008 at 01:43 UTC ( #663254=note: print w/ replies, xml ) Need Help??


in reply to Re: CGI::Application::Authentication and Static Pages
in thread CGI::Application::Authentication and Static Pages

I hate to write (ok it's a macro - but still) even the my $self = shift; part in each runmode - and you have the check in each one?

I've came up with this before Authen plugin was written ...

== this is the "base module shared by all - I use base *it* instead of + CGI::App directly. package YPTP::App; use strict; use base 'CGI::Application'; use base 'YPTP::DataBase'; use base 'YPTP::Email'; use CGI::Application::Plugin::TT; # TemplateToolkit use CGI::Application::Plugin::Session; # CGI::Session use CGI::Application::Plugin::AutoRunmode; sub cgiapp_init { my $self = shift; .... ussual setup stuff ... } # In case most of pages are public - if not I set it to return 0 sub authorize { my $self = shift; return 1; } sub cgiapp_prerun { my ($self, $run_mode) = @_; # CGI::APP doesn't alow you to change runmode at init stage - say +if there is an error with # DB connection ... So I set it there and catch it here. if( $self->param('error') ){ $self->prerun_mode('ERROR'); } # Maybe only some runmodes need to be protected - so we send the r +unmode name to decide unless( $self->authorize($run_mode) ){ # Error $self->prerun_mode('NOT_AUTHORIZED'); } } === some module containing runmodes connected logically package YPTP::Runmodes::Admin; use strict; use base 'YPTP::App'; sub authorize { my $self = shift; my $runmode = shift; my $type = $self->session->param('type'); return 1 if($type eq 'admin'); # admin can do anything return 0; # everyone else can't do a thing }
I'm obviously using CGI::Application::Dispatch to decide which file/module to call. So for each file containing runmodes you can override the default authorize method and even check auth based on runmode to be called.
sub authorize { my $self = shift; my $runmode = shift; my $tip = $self->session->param('tip'); return 1 if($tip eq 'admin'); # Admin moze sve ! :) my $auth = { 'index' => 1, # everyone profil_forma => $tip eq 'poslodavac', profil_obrada => $tip eq 'poslodavac', '_default' => $tip eq 'poslodavac' }; if(defined $auth->{$runmode}) { return $auth->{$runmode}; } else { return $auth->{_default}; } }

Have you tried freelancing? Check out Scriptlance - I work there. For more info about Scriptlance and freelancing in general check out my home node.


Comment on Re^2: CGI::Application::Authentication and Static Pages
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-07-28 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls