From 9ae27aaed7df10d51373d5ddf94d8479ade1071d Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 30 Dec 2010 15:28:24 +0100 Subject: [PATCH] =?utf8?q?Das=20L=C3=B6schen=20von=20Session-Keys=20auch?= =?utf8?q?=20au=C3=9Ferhalb=20von=20create=5For=5Frefresh=5Fsession()=20im?= =?utf8?q?plementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Auth.pm | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/SL/Auth.pm b/SL/Auth.pm index 7c9790462..120288755 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -597,7 +597,6 @@ sub create_or_refresh_session { if ($id) { do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id); - do_query($form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id); } else { do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR}); @@ -617,14 +616,20 @@ sub save_session { my $dbh = $provided_dbh || $self->dbconnect(); - my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|; - my $sth = prepare_query($::form, $dbh, $query); + do_query($::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id); - foreach my $key (sort keys %{ $self->{SESSION} }) { - do_statement($::form, $sth, $query, $session_id, $key, $self->{SESSION}->{$key}); + if (%{ $self->{SESSION} }) { + my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|; + my $sth = prepare_query($::form, $dbh, $query); + + foreach my $key (sort keys %{ $self->{SESSION} }) { + do_statement($::form, $sth, $query, $session_id, $key, $self->{SESSION}->{$key}); + } + + $sth->finish(); } - $sth->finish(); + $dbh->commit() unless $provided_dbh; } sub set_session_value { @@ -640,6 +645,32 @@ sub set_session_value { } $main::lxdebug->leave_sub(); + + return $self; +} + +sub delete_session_value { + $main::lxdebug->enter_sub(); + + my $self = shift; + + $self->{SESSION} ||= { }; + delete @{ $self->{SESSION} }{ @_ }; + + $main::lxdebug->leave_sub(); + + return $self; +} + +sub get_session_value { + $main::lxdebug->enter_sub(); + + my $self = shift; + my $value = $self->{SESSION} ? $self->_load_value($self->{SESSION}->{ $_[0] }) : undef; + + $main::lxdebug->leave_sub(); + + return $value; } sub set_cookie_environment_variable { -- 2.20.1