----- Original Message ----- From: "Kiffin Gish" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Tuesday, October 25, 2005 9:23 AM Subject: [Templates] Session handling using a plugin ...
> Hi there. > > I've been struggling around with a Session.pm plug-in I have created > based on CGI:Session and taking care that once users login, they remain > logged in until they either end the session or explicitly click on the > logout button. Also, the can check a 'remember me' checkbox to be logged > in automatically the next time around. > > Unfortunately I've been having alot of trouble getting the > session-cookie passed back and forth correctly. > > Using plain old Perl this is not a problem, but there is something weird > about the template-toolkit that is does something differently that I > don't understand. > > Does anyone else have any experience with this and have an example > (link) for me? > Sharing my experience, I've learned to give up on trying to program the framework around my application and use frameworks that others have bundled and made freely available. I once was following the same path as you, wasting time worring about cookies when what I really wanted to do was build and process web forms. In the application below, check out how by just saying "use CGI::Application::Plugin::Session;" my application has a full featured session object. Cookies? What are cookies? Dont know, dont care. I just know if I have a state maintaining obect in $self->session that very likely has been so well debugged that I can go straight to production with it. See it run at http://waveright.homeip.net/~trwww/app.cgi #!/usr/local/bin/perl use warnings; use strict; TestApp->new->run; package TestApp; use base qw|CGI::Application|; use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Session; sub default : StartRunmode { my $self = shift; my $output; # get current access count my $access_count = $self->session->param('access_count') || 1; # get CGI object out of application my $q = $self->query; #build output $output = $q->start_html( -title => 'access count application'); $output .= $q->div("accessed $access_count time(s) this session"); $output .= $q->div(' '); $output .= $q->div( $q->a( { -href => $q->self_url } => 'access again' ) ); # increment access count $self->session->param(access_count => $access_count + 1); # give output to app to send to user return( $output ); } _______________________________________________ templates mailing list [email protected] http://lists.template-toolkit.org/mailman/listinfo/templates
