I'm using older versions, C::A::P::Session v. 0.07 and CGI::Session 3.95.
And I store the sessions in MySQL (connect using C::A::P::DBH), but the 
following code may help you anyway:

# CGI::Application::Plugin::Session - configure the session
sub init_session {
  my $self = shift;
  $self->session_config(
                        CGI_SESSION_OPTIONS => [
                                                "driver:MySQL;id:MD5",
                                                $self->query,
                                                {
                                                 Handle     => $self->dbh,
                                                },
                                               ],
                        DEFAULT_EXPIRY      => '+1d',
                        COOKIE_PARAMS       => {
                                                -expires => '+1d',
                                                -path    => '/',
                                                -secure  => 1,
                                               },
                        SEND_COOKIE         => 1,
                       );
}
sub cgiapp_init  {
  my $self = shift;
  # (Any other init code here...)
  $self->init_session;
}
sub cgiapp_prerun {
  my $self = shift;
  # (Any other prerun code here...)
  # Session variables
  my $logged_in = $self->session->param('logged-in');
  if ($logged_in) {
    # Refresh the session login expiry time
    $self->session->expires('logged-in', '+30m');
  }
}  
sub login_check {
  my $self = shift;
  my $session = $self->session;
  # (authenticate against DB)
  if ($authenticated) {
    $session->param('logged-in' => 1);
  }
}
sub logout {
  my $self = shift;
  my $session = $self->session;
  $session->clear();
}


This link may help you as well:
http://cgiapp.erlbaum.net/cgi-bin/cgi-app/index.cgi?CgiApplicationPluginSessionExample

Regards,
Johan


On Friday 16 December 2005 22:01, [EMAIL PROTECTED] wrote:
> Seems like I have spent more time on C::A::P::Session than all the other
> plugins combined--and I just can't get it to work. It is setting a session
> in cgiapp_postrun after logging in for the first time (it is also setting
> a cookie very nicely). This is evidenced by the line: 'logged_in: 1" in my
> debug2.txt file and the visual setting of the cookie.
>
> However, when I come return from the next HTML page to execute another
> runmode, the session is coming up empty. This is evidenced by the line:
> 'logged_in: ' in my debug1.txt file.
>
> In good olde CGI::Session, I have to use the session id to retrieve the
> session:
>
>    my $session_id = cookie('CGISESSID');
>    my $session = new CGI::Session("driver:File", $session_id,
> {Directory=>'/tmp'});
>
>
> I see that an id is created in the cookie by C::A::P::S, but how is it use
> to retrieve the session, if at all? Here's my bare bones code:
>
> sub cgiapp_init {
>    my $self = shift;
>
>    $self->session_config(
>        CGI_SESSION_OPTIONS => [ "driver:File", $self->query,
> {Directory=>'/tmp'} ],
>        DEFAULT_EXPIRY      => '+15m',
>        COOKIE_PARAMS       => { -name    => 'designsoft',
>                                 -path    => '/'},
>        SEND_COOKIE         => 1);
>
> open (DEBUG, ">debug1.txt") or die "debug error: $!";
> print DEBUG "logged_in:". $self->session->param('logged_in')."\n"; close
> DEBUG;
> }
>
> sub cgiapp_prerun {
>    if ($self->session->param('logged_in')) {    # if logged in then grab
> the rest of the session
>       $user_name     = $self->session->param('user_name');
>       $user_id       = $self->session->param('user_id');
>
>    } elsif ($query->param('rm') eq "li") {  #If attempted to log in
>       $self->prerun_mode('li');            #  run log-in mode
>    } else {                                 #If not logged in
>       $self->prerun_mode('sl');            #  then show form
>    }
> }
>
> sub cgiapp_postrun {
>    my $self = shift;
>    $self->set_session(); #set the session
> }
>
> sub set_session {
>    my $self = shift;
>    $self->session->param(user_name     => $user_name);
>    $self->session->param(user_id       => $user_id);
>    $self->session->param(logged_in     => 1); #persistent
>
> open (DEBUG, ">debug2.txt") or die "debug error: $!";
> print DEBUG "logged_in:". $self->session->param('logged_in')."\n"; close
> DEBUG;
> }
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> Web Archive:  http://www.mail-archive.com/cgiapp@lists.erlbaum.net/
>               http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Johan Kuuse
[EMAIL PROTECTED]
Fri Dec 16 22:48:26 2005


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@lists.erlbaum.net/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to