Revision 263
- Date:
- 2013/01/15 13:42:20
- Files:
Legend:
- Added
- Removed
- Modified
-
utf8/plugins/session/lib/session/Keeper.pm
54 54 55 55 sub logoff { 56 56 my $self = shift; 57 my %opts = @_; 57 my (%opts) = @_; 58 58 59 59 my $sid = _get_session_id (); 60 60 my $session = _get_session_object ( $sid ); … … 63 63 my $session_id = $session->{_session_id}; 64 64 if (!$sid || $sid ne $session_id) { 65 65 warn "LOGOFF: New or deprecated session. Old sid = '$sid', new sid = '$session_id'" if $DEBUG; 66 _store_session_id ($session_id) 66 _store_session_id ($session_id, %opts) 67 67 } else { 68 68 if ( exists $opts{clear} ) { 69 69 my @clear = qw( id email login name nick type status ltime ); … … 114 114 115 115 sub get_value { 116 116 117 my ($self, $name) = @_; 118 my $sid = _get_session_id (); 117 my ($self, $name, %opts) = @_; 118 my $sid = delete $opts{_session_id} || _get_session_id (); 119 119 my $session = _get_session_object ( $sid ); 120 120 return unless ref $session; 121 121 … … 123 123 my $value = $session->{$name}; 124 124 if (!$sid || $sid ne $session_id) { 125 125 warn "GET_VALUE: New or deprecated session. Old sid = '$sid', new sid = '$session_id'" if $DEBUG; 126 _store_session_id ($session_id); 126 _store_session_id ($session_id, %opts); 127 127 } 128 128 untie %$session; 129 129 return $value; … … 133 133 sub store_value { 134 134 135 135 my ($self, %opts) = @_; 136 my $sid = _get_session_id (); 136 my $domain = delete $opts{domain}; 137 my $sid = delete $opts{_session_id} || _get_session_id (); 137 138 my $session = _get_session_object ( $sid ); 138 139 return unless ref $session; 139 140 … … 144 145 my $session_id = $session->{_session_id}; 145 146 if (!$sid || $sid ne $session_id) { 146 147 warn "STORE_VALUE: New or deprecated session. Old sid = '$sid', new sid = '$session_id'" if $DEBUG; 147 _store_session_id ($session_id); 148 _store_session_id ($session_id, domain => $domain); 148 149 } 149 150 untie %$session; 150 151 return 1; … … 153 154 154 155 sub delete_key { 155 156 156 my ($self, $key) = @_; 157 my ($self, $key, %opts) = @_; 157 158 return unless $key; 158 159 159 my $sid = _get_session_id (); 160 my $sid = delete $opts{_session_id} || _get_session_id (); 160 161 my $session = _get_session_object ( $sid ); 161 162 return unless ref $session; 162 163 163 164 my $session_id = $session->{_session_id}; 164 165 if (!$sid || $sid ne $session_id) { 165 166 warn "DELETE_VALUE: New or deprecated session. Old sid = '$sid', new sid = '$session_id'" if $DEBUG; 166 _store_session_id ($session_id); 167 _store_session_id ($session_id, %opts); 167 168 } else { 168 169 delete $session->{$key} if exists $session->{$key}; 169 170 } … … 175 176 sub get_session { 176 177 177 178 my $self = shift; 179 my (%opts) = @_; 178 180 179 181 my $sid = _get_session_id () || ''; 180 182 my $session = _get_session_object ($sid); … … 184 186 my %ret = %$session; 185 187 if (!$sid || $sid ne $session_id) { 186 188 warn "\nGET_SESSION: New or deprecated session. Old sid = '$sid', new sid = '$session_id'\n" if $DEBUG; 187 _store_session_id ($session_id); 189 _store_session_id ($session_id, %opts); 188 190 } 189 191 untie %$session; 190 192 … … 197 199 sub _store_session_id { 198 200 199 201 my $sid = shift; 202 my (%opts) = @_; 200 203 return unless $sid; 201 204 my $cookie = Apache::Cookie->new ($request->r(), 202 -domain => $state->{session}->domain, 205 -domain => $opts{domain} || $state->{session}->domain, 203 206 -name => $state->{session}->cookie, 204 207 -expires=> $state->{session}->expires, 205 208 -value => $sid, … … 212 215 213 216 sub _get_session_id { 214 217 218 my $keyname = shift || $state->{session}->cookie; 219 215 220 my %cookies = Apache::Cookie->fetch; 216 221 warn Dumper(\%cookies) if $DEBUG; 217 my $cookie = $cookies{$state->{session}->cookie}; 222 my $cookie = $cookies{$keyname}; 218 223 219 224 # Вытаскиваем SID из куки 220 225 my $sid = $cookie->value() || '' if $cookie; … … 253 258 if ($@) { 254 259 warn "Session data is not accessible: $@"; 255 260 undef $sid; 256 } elsif ( $state->{session}->lifetime ) { 257 unless ( exists $session{_timestamp} ) { 258 $session{_timestamp} = $now; 259 } elsif ( ($now - $session{_timestamp}) > $state->{session}->lifetime ) { 260 undef $sid; 261 } elsif ( ($now - $session{_timestamp}) > $state->{session}->checkout ) { 262 $session{_timestamp} = $now; 261 } else { 262 $sid = $session{_session_id}; 263 if ( $state->{session}->lifetime ) { 264 unless ( exists $session{_timestamp} ) { 265 $session{_timestamp} = $now; 266 } elsif ( ($now - $session{_timestamp}) > $state->{session}->lifetime ) { 267 undef $sid; 268 } elsif ( ($now - $session{_timestamp}) > $state->{session}->checkout ) { 269 $session{_timestamp} = $now; 270 } 263 271 } 264 272 } 265 273 unless ( $sid ) {