Ed Pigg wrote:
On Apr 29, 2006, at 2:28 PM, Ed Pigg wrote:
Changes to the derived package adding
use base 'myapp::Base';
__PACKAGE__->authen->protected_runmodes(':all');
.....
added the login run_mode from the base class and now I am getting
the login run_mode when attempting to access the derived class
without logging in. I have not tested other calls. I'm still
working on the authentication aspect.
sub setup {
my $self = shift;
$self->runmodes( { 'login' => 'login', login is in
base class
'others....
for clarity
I tend to put run modes that are common to all derived apps, like "login", in
my base class. This would be part of my base class:
package My::BaseApp;
use strict;
use warnings;
use base qw/ CGI::Application /;
use CGI::Application::Plugin::Authentication;
my $user_map = {
rhesa => 'secret',
root => 'invisible_password',
};
sub cgiapp_init
{
my $self = shift;
$self->error_mode('oops');
$self->run_modes( [qw/ logout overview /] );
# login is already supplied by
# CAP::Authentication.
# See its docs on how to override.
$self->authen->config(
DRIVER => [ 'Generic', $user_map ],
LOGOUT_RUNMODE => 'logout',
POST_LOGIN_RUNMODE => 'overview',
);
$self->authen->protected_runmodes(':all');
}
sub overview
{
my $self = shift;
return $self->load_tmpl('overview.html')->output;
}
sub logout
{
my $self = shift;
$self->authen->logout;
return $self->redirect('/staff');
}
1;
An example reporting app then looks like this:
package My::Reporting;
use strict;
use warnings;
use base qw/ My::BaseApp /;
use My::Orders;
use My::Traffic;
sub setup
{
my $self = shift;
$self->start_mode('overview'); # defined in base class
$self->run_modes([ qw/
traffic_report
sales_report
/ ]); # these are all protected
# by CAP::Authentication
}
sub traffic_report
{
my $self = shift;
my $report = $self->load_tmpl('traffic_report.html');
$report->param( My::Traffic->report );
return $report->output;
}
sub sales_report
{
# something similar
}
1;
As you can see, most of the common behaviour is in My::BaseApp, and that makes
the actual app classes pretty clean.
Rhesa
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]