Revision 8431ef24
Von Sven Schöling vor mehr als 13 Jahren hinzugefügt
SL/Auth.pm | ||
---|---|---|
598 | 598 |
} |
599 | 599 |
|
600 | 600 |
sub create_or_refresh_session { |
601 |
$main::lxdebug->enter_sub(); |
|
602 |
|
|
603 |
my $self = shift; |
|
604 |
|
|
605 |
$session_id ||= $self->_create_session_id(); |
|
606 |
|
|
607 |
my ($form, $dbh, $query, $sth, $id); |
|
608 |
|
|
609 |
$form = $main::form; |
|
610 |
$dbh = $self->dbconnect(); |
|
611 |
|
|
612 |
$dbh->begin_work; |
|
613 |
do_query($::form, $dbh, qq|LOCK auth.session_content|); |
|
614 |
|
|
615 |
$query = qq|SELECT id FROM auth.session WHERE id = ?|; |
|
616 |
|
|
617 |
($id) = selectrow_query($form, $dbh, $query, $session_id); |
|
618 |
|
|
619 |
if ($id) { |
|
620 |
do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id); |
|
621 |
|
|
622 |
} else { |
|
623 |
do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR}); |
|
624 |
|
|
625 |
} |
|
626 |
|
|
627 |
$self->save_session($dbh); |
|
628 |
|
|
629 |
$dbh->commit(); |
|
630 |
|
|
631 |
$main::lxdebug->leave_sub(); |
|
601 |
$session_id ||= shift->_create_session_id; |
|
632 | 602 |
} |
633 | 603 |
|
634 | 604 |
sub save_session { |
... | ... | |
645 | 615 |
do_query($::form, $dbh, qq|LOCK auth.session_content|); |
646 | 616 |
do_query($::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id); |
647 | 617 |
|
618 |
my $query = qq|SELECT id FROM auth.session WHERE id = ?|; |
|
619 |
|
|
620 |
my ($id) = selectrow_query($::form, $dbh, $query, $session_id); |
|
621 |
|
|
622 |
if ($id) { |
|
623 |
do_query($::form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id); |
|
624 |
} else { |
|
625 |
do_query($::form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR}); |
|
626 |
} |
|
627 |
|
|
648 | 628 |
if (%{ $self->{SESSION} }) { |
649 | 629 |
my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|; |
650 | 630 |
my $sth = prepare_query($::form, $dbh, $query); |
Auch abrufbar als: Unified diff
Session nur einmal pro Request speichern, und zwar danach.
Vorher wurde die Session mindestens zweimal vor dem Request gespechert. Unnötig.