Author: spadkins
Date: Thu Sep 13 13:06:46 2007
New Revision: 9946
Modified:
p5ee/trunk/App-Context/lib/App/Session/HTMLHidden.pm
Log:
Changes for application login logoff
Modified: p5ee/trunk/App-Context/lib/App/Session/HTMLHidden.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Session/HTMLHidden.pm (original)
+++ p5ee/trunk/App-Context/lib/App/Session/HTMLHidden.pm Thu Sep 13
13:06:46 2007
@@ -188,6 +188,30 @@
$html .= "-->\n";
}
+ my $app = $options->{"app"};
+ my $cookie_attribs = $options->{"app.Session.cookie_attribs"};
+ if ($cookie_attribs) {
+ my $cookiedata = {};
+ foreach my $cookie_attrib (split(/[ ,;]+/, $cookie_attribs)) {
+ if ($cookie_attrib =~ /^([^-]+)-(.+)$/) {
+ $cookiedata->{$1}{$2} = $sessiondata->{SessionObject}{$1}{$2};
+ }
+ elsif ($cookie_attrib) {
+ $cookiedata->{default}{$cookie_attrib} =
+ $sessiondata->{SessionObject}{default}{$cookie_attrib};
+ }
+ }
+
+ my $cgi = $self->{context}->request()->{cgi};
+ my $secure = ($cgi->url() =~ /^https/) ? "; secure" : "";
+
+ my $cookietext =
MIME::Base64::encode(Compress::Zlib::memGzip(freeze($cookiedata)));
+ $cookietext =~ s/\n//g; # get rid of newlines (76 char lines)
+ my $cookie_options = $options->{"app.Session.cookie_options"} ||
"$secure";
+ my $headers = "Set-Cookie:
app_session_${app}_persist=$cookietext$cookie_options\n";
+ $self->{context}->set_header($headers);
+ }
+
&App::sub_exit($html) if ($App::trace);
$html;
}
@@ -243,6 +267,7 @@
$store = {};
$cgi = $args->{cgi} if (defined $args);
$cgi = $self->{context}->request()->{cgi} if (!defined $cgi);
+
if (defined $cgi) {
$sessiontext = $cgi->param("app.sessiondata");
if ($sessiontext) {
@@ -257,6 +282,37 @@
$store =
thaw(Compress::Zlib::memGunzip(decode_base64($sessiontext)));
}
}
+
+ my $options = $self->{context}{options};
+ my $cookie_attribs = $options->{"app.Session.cookie_attribs"};
+ if ($cookie_attribs) {
+ my $cookiedata = {};
+
+ my $app = $options->{"app"};
+ my $cookietext = $cgi->cookie("app_session_${app}_persist");
+ if ($cookietext) {
+ $cookietext =~ s/ /\+/g;
+ my $length = length($cookietext);
+ my $pad = 4 - ($length % 4);
+ $pad = 0 if ($pad == 4);
+ $cookietext .= ("=" x $pad) if ($pad);
+ $cookietext =~ s/(.{76})/$1\n/g;
+ $cookietext .= "\n";
+#print "Session::Cookie->_init(): sessiontext = [\n$sessiontext\n]\n";
+ $cookiedata =
thaw(Compress::Zlib::memGunzip(MIME::Base64::decode($cookietext)));
+ }
+
+ foreach my $cookie_attrib (split(/[ ,;]+/, $cookie_attribs)) {
+ if ($cookie_attrib =~ /^([^-]+)-(.+)$/) {
+ $store->{SessionObject}{$1}{$2} = $cookiedata->{$1}{$2};
+ }
+ elsif ($cookie_attrib) {
+ $store->{SessionObject}{default}{$cookie_attrib} =
+ $cookiedata->{default}{$cookie_attrib};
+ }
+ }
+ }
+
$self->{context} = $args->{context} if (defined $args->{context});
$self->{store} = $store;
$self->{cache} = {};