Re: [cgiapp] C::A::P::Session not 'remembering' session

2005-12-17 Thread bradford
Cees:

 That is odd, as it usually works out of the box without requiring any
 configuration.

You're absolutely right. I was just trying too hard. After commenting out
session_config and having it work, I successfully added back in:

 $self-session_config( DEFAULT_EXPIRY  = '+15m');

As I am finding with all of C::A stuff (this being my first week using
C::A and the plug-ins) is that it's almost *too* easy. I was telling a
fellow coder, who has yet to make the switch, that I'm incredulous
everytime I use a new plug-in (once I get them installed).

Anyway, hats off to all those who have contributed to the C::A way, the
Perlmonks that pushed me in the first place (guilt),  and for this
list-serve that has made the jump so much easier for me.

Brad



 On 12/16/05, [EMAIL PROTECTED] [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.

 That is odd, as it usually works out of the box without requiring any
 configuration.

 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'});

 Actually, you don't have to do that with CGI::Session, you can just
 give it a CGI.pm object and it will figure out the session_id from
 that.  That is the technique that CAP::Session uses.

 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);

 What you are doing here is telling CAP::Session to use a different
 name for the cookie.  The docs for CAP::Session warn you about doing
 that.  My recommendation would be to comment out your entire
 'session_config'  line and let CAP::Session use its defaults.  That
 should work for everyone.  Then you can start adding customizations in
 and test as you make changes.  That way you will figure out where
 things are going wrong.

 Cheers,

 Cees




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



[cgiapp] C::A::P::Session not 'remembering' session

2005-12-16 Thread bradford
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=cgiappr=1w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [cgiapp] C::A::P::Session not 'remembering' session

2005-12-16 Thread Johan Kuuse
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=cgiappr=1w=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=cgiappr=1w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]