CGI-Application-Plugin-Authentication
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/Authentication.pm view on Meta::CPAN
# this login has timed out
$self->{is_login_timeout} = 1;
$self->logout;
}
}
return 1;
}
=head2 display
This method will return the
L<CGI::Application::Plugin::Authentication::Display> object, creating
and caching it if necessary.
=cut
sub display {
my $self = shift;
return $self->{display} if $self->{display};
my $config = $self->_config->{LOGIN_FORM} || {};
my $class = "CGI::Application::Plugin::Authentication::Display::".
($config->{DISPLAY_CLASS} || 'Classic');
$class->require;
$self->{display} = $class->new($self->_cgiapp);
return $self->{display};
}
=head2 login_box
This method will return the HTML for a login box that can be
embedded into another page. This is the same login box that is used
in the default authen_login runmode that the plugin provides.
This function will initiate a session or cookie if one has not been created already.
=cut
sub login_box {
my $self = shift;
return $self->display->login_box;
}
=head2 new
This method creates a new CGI::Application::Plugin::Authentication object. It requires
as it's only parameter a CGI::Application object. This method should never be called
directly, since the 'authen' method that is imported into the CGI::Application module
will take care of creating the CGI::Application::Plugin::Authentication object when it
is required. Calling this function, will not itself generate cookies or session ids.
=cut
sub new {
my $class = shift;
my $cgiapp = shift;
my $self = {};
bless $self, $class;
$self->{cgiapp} = $cgiapp;
Scalar::Util::weaken($self->{cgiapp}); # weaken circular reference
return $self;
}
=head2 instance
This method works the same way as 'new', except that it returns the same Authentication
object for the duration of the request. This method should never be called
directly, since the 'authen' method that is imported into the CGI::Application module
will take care of creating the CGI::Application::Plugin::Authentication object when it
is required. Calling this function, will not itself generate cookies or session ids.
=cut
sub instance {
my $class = shift;
my $cgiapp = shift;
die "CGI::Application::Plugin::Authentication->instance must be called with a CGI::Application object"
unless defined $cgiapp && UNIVERSAL::isa( $cgiapp, 'CGI::Application' );
$cgiapp->{__CAP_AUTHENTICATION_INSTANCE} = $class->new($cgiapp) unless defined $cgiapp->{__CAP_AUTHENTICATION_INSTANCE};
return $cgiapp->{__CAP_AUTHENTICATION_INSTANCE};
}
=head1 CGI::Application CALLBACKS
=head2 prerun_callback
This method is a CGI::Application prerun callback that will be
automatically registered for you if you are using CGI::Application
4.0 or greater. If you are using an older version of CGI::Application
you will have to create your own cgiapp_prerun method and make sure you
call this method from there.
sub cgiapp_prerun {
my $self = shift;
$self->CGI::Application::Plugin::Authentication::prerun_callback();
}
=cut
sub prerun_callback {
my $self = shift;
my $authen = $self->authen;
$authen->initialize;
# setup the default login and logout runmodes
$authen->setup_runmodes;
# The user is asking to be logged out
if (scalar $self->query->param('authen_logout')) {
# The user wants to logout
return $self->authen->redirect_to_logout;
}
# If the user just logged in then we may want to redirect them
if ($authen->is_new_login) {
( run in 2.406 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )