[cgiapp] cgiapp_postrun

2005-12-16 Thread Brad Cathey
Hello again,

I'm trying to understand exactly what postrun allows me to do.

I would like to have it set a new session (via C:P:A:Session) before the
script outputs my .tmpl page. This code produces an error:

Error executing class callback in postrun stage: Can't call method
'session' on an undefined value at...

It may have nothing to do with my postrun, but I'm still curious.

Thanks all!

Here's the salient code:

sub cgiapp_init {
my $self = shift;
$self-session_config(
   CGI_SESSION_OPTIONS  = [ driver:File, $self-query,
{Directory='/tmp'} ],
   DEFAULT_EXPIRY   = '+15m',
   COOKIE_PARAMS= { -path= '/' },
   SEND_COOKIE  = 1);
}

sub setup {
my $self = shift;
$self-start_mode('sh');
$self-mode_param('rm');   #return $self-forward('other_action');
$self-run_modes(
  'sh'= 'show_home',
  'sl'= 'show_login',#show login screen
  'li'= 'log_in',#attempt login
);
}

sub cgiapp_postrun {
my $self = shift;
set_session(); 
}

sub show_home {
my $self = shift;
my $template = $self-load_tmpl( 'home.tmpl');
return $template-output;
}

sub set_session {
my $self = shift;
$self-session-param(user_name   = $user_name);
$self-session-param(user_id = $user_id);
$self-session-param(admin   = $admin);
$self-session-param(logged_in   = 1);
}

Brad



-
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] cgiapp_postrun

2005-12-16 Thread Brad Cathey
Thanks Michael. It worked and I learned something. Not sure I understand it
fully, but the light went on. I need to have a better understanding of OO.
Objects, instances, methods are still a mystery to me. It's kinda like
knowing how to drive, but not knowing how an internal combustion engine
works. I want to know more about the engine.

Thanks again.


 
 
 Brad Cathey wrote:
 Hello again,
 
 I'm trying to understand exactly what postrun allows me to do.
 
 I would like to have it set a new session (via C:P:A:Session) before the
 script outputs my .tmpl page. This code produces an error:
 
 Error executing class callback in postrun stage: Can't call method
 'session' on an undefined value at...
 
 It may have nothing to do with my postrun, but I'm still curious.
 
 It doesn't have anything to do with cgiapp_postrun() but rather how your
 calling
 a subroutine.
 [snip]
 
 sub cgiapp_postrun {
 my $self = shift;
 set_session();
 }
 
 [snip]
 
 sub set_session {
 my $self = shift;
 $self-session-param(user_name   = $user_name);
 $self-session-param(user_id = $user_id);
 $self-session-param(admin   = $admin);
 $self-session-param(logged_in   = 1);
 }
 
 Here you're calling set_session() but not passing any arguments to it. Then in
 the set_session() sub your using 'shift' to pull out the arguments. So your
 $self is undefined. You need to call set_session() like either of these 2
 examples:
 
   $self-set_session();
 or
   set_session($self);
 
 The first one is clearest since set_session() is clearly intended to be a
 method.



-
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] cgiapp_postrun

2005-12-16 Thread Michael Peters


Brad Cathey wrote:
 Thanks Michael. It worked and I learned something. Not sure I understand it
 fully, but the light went on. I need to have a better understanding of OO.
 Objects, instances, methods are still a mystery to me. It's kinda like
 knowing how to drive, but not knowing how an internal combustion engine
 works. I want to know more about the engine.

Try
  perldoc perltoot

It's a nice intro to OO and especially Perl OO

-- 
Michael Peters
Developer
Plus Three, LP


-
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] Re: CGI::Uploader and mimetypes

2005-12-16 Thread Jeff MacDonald
 Note: My version of File::Temp (0.14) for Perl 5.8.6 uses tmpdir(),
 not curdir(). You might want to upgrade File::Temp before doing
 anything drastic.

I'm running File::Temp 0.16 and it appear to use curdir.. Which line
of code are you refering to ?

I jsut read the changelog for this module and it doesn't really make
any mention of chaning whether it uses curdir or tmpdir.

I upgraded to the CGI::Uploader that Mark posted and it still tries to
make a tmpfile in . which is my cgi-bin.

So I think the explicit patch is necessary.

 Of course, upgrade CGI::Uploader to be explict about these things
 isn't a bad idea. Explicit is always good.

 Rob

 -
 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]




--
Jeff MacDonald
http://www.halifaxbudolife.ca
http://www.nintai.ca

-
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] Re: CGI::Uploader and mimetypes

2005-12-16 Thread Jeff MacDonald
Here is the patch

change line 616 to this

   my ($tmp_fh, $tmp_filename) = tempfile('CGIuploaderX', UNLINK
= 1, DIR = File::Spec-tmpdir());

:)

I'll make a real patch for the mime stuff.

Jeff.

On 12/16/05, Jeff MacDonald [EMAIL PROTECTED] wrote:
  Note: My version of File::Temp (0.14) for Perl 5.8.6 uses tmpdir(),
  not curdir(). You might want to upgrade File::Temp before doing
  anything drastic.

 I'm running File::Temp 0.16 and it appear to use curdir.. Which line
 of code are you refering to ?

 I jsut read the changelog for this module and it doesn't really make
 any mention of chaning whether it uses curdir or tmpdir.

 I upgraded to the CGI::Uploader that Mark posted and it still tries to
 make a tmpfile in . which is my cgi-bin.

 So I think the explicit patch is necessary.

  Of course, upgrade CGI::Uploader to be explict about these things
  isn't a bad idea. Explicit is always good.
 
  Rob
 
  -
  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]
 
 


 --
 Jeff MacDonald
 http://www.halifaxbudolife.ca
 http://www.nintai.ca



--
Jeff MacDonald
http://www.halifaxbudolife.ca
http://www.nintai.ca

-
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] Re: CGI::Uploader and mimetypes

2005-12-16 Thread Jeff MacDonald
Actually I just read the wishlist, i'll make it an option and work on the tests

might as well do it right



On 12/16/05, Jeff MacDonald [EMAIL PROTECTED] wrote:
 Here is the patch

 change line 616 to this

my ($tmp_fh, $tmp_filename) = tempfile('CGIuploaderX', UNLINK
 = 1, DIR = File::Spec-tmpdir());

 :)

 I'll make a real patch for the mime stuff.

 Jeff.

 On 12/16/05, Jeff MacDonald [EMAIL PROTECTED] wrote:
   Note: My version of File::Temp (0.14) for Perl 5.8.6 uses tmpdir(),
   not curdir(). You might want to upgrade File::Temp before doing
   anything drastic.
 
  I'm running File::Temp 0.16 and it appear to use curdir.. Which line
  of code are you refering to ?
 
  I jsut read the changelog for this module and it doesn't really make
  any mention of chaning whether it uses curdir or tmpdir.
 
  I upgraded to the CGI::Uploader that Mark posted and it still tries to
  make a tmpfile in . which is my cgi-bin.
 
  So I think the explicit patch is necessary.
 
   Of course, upgrade CGI::Uploader to be explict about these things
   isn't a bad idea. Explicit is always good.
  
   Rob
  
   -
   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]
  
  
 
 
  --
  Jeff MacDonald
  http://www.halifaxbudolife.ca
  http://www.nintai.ca
 


 --
 Jeff MacDonald
 http://www.halifaxbudolife.ca
 http://www.nintai.ca



--
Jeff MacDonald
http://www.halifaxbudolife.ca
http://www.nintai.ca

-
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] Re: C::A::P::Session

2005-12-16 Thread Mark Stosberg
On 2005-12-16, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 2) why do coders preface 'logged-in' with a tilde, e.g., '~logged-in'?
 What's wrong with 'logged-in'?

I wouldn't say that coders prefer the tilde. I think it is visual noise,
like the extra dashes in the CGI.pm interface:

popup_menu(
-name ...
-labels ...
);

Mark


-
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]