#!/usr/bin/perl -w package testapp; use base qw( CGI::Application ); use strict; use CGI; use CGI::Session; use CGI::Session::Auth; use CGI::Carp; use Data::Dumper::HTML qw(dumper_html); sub setup { my $self = shift; $self->start_mode('free'); $self->mode_param('cmd'); $self->run_modes( 'free' => 'showFreePage', 'secret' => 'showSecretPage', 'logout' => 'showLogoutPage', ); # new session object my $session = new CGI::Session(undef, $self->query, {Directory=>'/tmp'}); $self->param('_session' => $session); # new authentication object my $auth = new CGI::Session::Auth({ CGI => $self->query, Session => $session }); $self->param('_auth' => $auth); $auth->authenticate(); # send session cookie $self->header_props( -cookie => $auth->sessionCookie() ); } sub _auth { my $self = shift; return $self->param('_auth'); } sub showFreePage { my $self = shift; return <
Please log in to see the secret page:
HTML } sub showSecretData { my $self = shift; my $var = dumper_html($self->_auth); return <$var
There's more than one way to do it!
HTML } sub showLogoutPage { my $self = shift; $self->_auth->logout(); return <