From:
<a_...@us...> - 2006-09-30 02:03:50
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11840/lib/OpenInteract2 Modified Files: SessionManager.pm Response.pm Log Message: hashref sessions are now stored as sessions using the configured implementation class (and thus saved at all). Sessionmanager has a method for removing session from the datastore and removing the keys from it so that a new session object is not created at the end of the response with the same data. Logout now uses this method. Index: SessionManager.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/SessionManager.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SessionManager.pm 25 Jan 2006 11:55:51 -0000 1.10 --- SessionManager.pm 30 Sep 2006 02:03:46 -0000 1.11 *************** *** 31,34 **** --- 31,36 ---- $log->warn( "Error fetching session with ID '$session_id': $@\n", "Continuing..." ); + # This cookie expire is overridden if the returned "session hash" + # gets values and a new session cookie is created from it. OpenInteract2::Cookie->expire( SESSION_COOKIE ); return {}; *************** *** 45,54 **** $log->is_info && $log->info( "Session is expired; clearing out." ); ! eval { tied( %{ $session } )->delete() }; ! if ( $@ ) { ! $log->warn( "Caught error trying to remove expired session: $@\n", ! "Continuing without problem since this just means", ! "you'll have a stale session in your datastore" ); ! } return {}; } --- 47,51 ---- $log->is_info && $log->info( "Session is expired; clearing out." ); ! $class->delete_session( $session ); return {}; } *************** *** 61,64 **** --- 58,83 ---- + sub delete_session { + my ( $class, $session ) = @_; + + return 0 if ! ref $session; + if ( tied( %{ $session } ) ) { + eval { tied( %{ $session } )->delete() }; + if ( $@ ) { + $log->warn( + "Caught error trying to remove session: $@\n", + "Continuing without problem since this just means", + "you'll have a stale session in your datastore" + ); + } + untie %{ $session }; + } + + delete $session->{ $_ } for keys %{ $session }; + + return 1; + } + + sub is_session_valid { my ( $class, $session ) = @_; *************** *** 125,129 **** $log->is_debug && $log->debug( "Tied session, no useful info; removing..." ); ! tied( %{ $session } )->delete(); } } --- 144,148 ---- $log->is_debug && $log->debug( "Tied session, no useful info; removing..." ); ! $class->delete_session( $session ); } } *************** *** 138,147 **** $log->is_info && $log->info( "Create new session with data from hashref using ", ! "keys: ", keys %{ $session } ); my $new_session = $class->create; if ( $new_session ) { foreach my $key ( keys %{ $session } ) { $new_session->{ $key } = $session->{ $key }; } $class->_save_session( $new_session, 1 ); } --- 157,168 ---- $log->is_info && $log->info( "Create new session with data from hashref using ", ! "keys: ", join (', ', keys %{ $session } ) ); my $new_session = $class->create; if ( $new_session ) { foreach my $key ( keys %{ $session } ) { + next if $key eq '_session_id'; $new_session->{ $key } = $session->{ $key }; } + delete $new_session->{is_new}; $class->_save_session( $new_session, 1 ); } *************** *** 249,253 **** # Saving a session is done in OpenInteract2::Response ! OpenInteract2::SessionManager->save( CTX->request->session ); =head1 DESCRIPTION --- 270,282 ---- # Saving a session is done in OpenInteract2::Response ! my $session_class = CTX->lookup_session_config->{class}; ! $session_class->save( CTX->request->session ); ! ! # When logging out, in addition to clearing the session cookie, ! # you might want to remove the session from the datastore: ! ! OpenInteract2::SessionManager->delete_session( ! CTX->request->session ! ); =head1 DESCRIPTION *************** *** 257,262 **** L<Apache::Session|Apache::Session> to do the heavy-lifting for us. ! This handler has two public methods: C<create()> and C<save()>. Guess ! in which order they are meant to be called? This class also requires you to implement a subclass that overrides --- 286,294 ---- L<Apache::Session|Apache::Session> to do the heavy-lifting for us. ! This handler has two main public methods: C<create()> and C<save()>. ! Create is used to create session objects (both old ones using stored ! data and new ones with no data). ! Save is used to make sure that the given data is stored in a session ! object and the object id is set in a session cookie. This class also requires you to implement a subclass that overrides *************** *** 291,298 **** hashref if not. ! B<save()> ! Persist (create or update) the session for later. If the 'is_new' key ! was set in the session by the C<create()> method we also use L<OpenInteract2::Cookie|OpenInteract2::Cookie> to create a new cookie and put it in the response. The expiration for the generated cookie is --- 323,334 ---- hashref if not. ! B<save( $session object | $hashref of values )> ! Persist (create or update) the session data for later. If a hashref is ! given, a new session object is created with the given data and a ! random session id. ! ! If the 'is_new' key was set in the session by the C<create()> method ! or a new object was created from a hashref we also use L<OpenInteract2::Cookie|OpenInteract2::Cookie> to create a new cookie and put it in the response. The expiration for the generated cookie is *************** *** 305,308 **** --- 341,349 ---- This method will not serialize the session if it is empty. + B<delete_session( $session object | $hashref of values )> + + Deletes the data tied to the session object, unties the object + and removes all keys from the remaining hashref. + =head1 CONFIGURATION Index: Response.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Response.pm,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Response.pm 21 Sep 2005 04:09:20 -0000 1.29 --- Response.pm 30 Sep 2006 02:03:46 -0000 1.30 *************** *** 160,164 **** sub save_session { my ( $self ) = @_; ! OpenInteract2::SessionManager->save( CTX->request->session ); } --- 160,165 ---- sub save_session { my ( $self ) = @_; ! my $session_class = CTX->lookup_session_config->{class}; ! $session_class->save( CTX->request->session ); } |