forward porting safe token code
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 13 Feb 2007 18:42:42 +0000 (18:42 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 13 Feb 2007 18:42:42 +0000 (18:42 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6944 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm

index 5043eb7..4c8d60a 100644 (file)
@@ -2582,6 +2582,56 @@ sub session_home_lib {
        return $org->shortname;
 }
 
+__PACKAGE__->register_method(
+       method => 'session_safe_token',
+       api_name => 'open-ils.actor.session.safe_token',
+       signature => q/
+               Returns a hashed session ID that is safe for export to the world.
+               This safe token will expire after 1 hour of non-use.
+               @param auth Active authentication token
+       /
+);
+
+sub session_safe_token {
+       my( $self, $conn, $auth ) = @_;
+       my $e = new_editor(authtoken=>$auth);
+       return undef unless $e->checkauth;
+
+       my $safe_token = md5_hex($auth);
+
+       $cache ||= OpenSRF::Utils::Cache->new("global", 0);
+
+       # Add more like the following if needed...
+       $cache->put_cache(
+               "safe-token-home_lib-shortname-$safe_token",
+               $e->retrieve_actor_org_unit(
+                       $e->requestor->home_ou
+               )->shortname,
+               60 * 60
+       );
+
+       return $safe_token;
+}
+
+
+__PACKAGE__->register_method(
+       method => 'safe_token_home_lib',
+       api_name => 'open-ils.actor.safe_token.home_lib.shortname',
+       signature => q/
+               Returns the home library shortname from the session
+               asscociated with a safe token from generated by
+               open-ils.actor.session.safe_token.
+               @param safe_token Active safe token
+       /
+);
+
+sub safe_token_home_lib {
+       my( $self, $conn, $safe_token ) = @_;
+
+       $cache ||= OpenSRF::Utils::Cache->new("global", 0);
+       return $cache->get_cache( 'safe-token-home_lib-shortname-'. $safe_token );
+}
+
 
 
 __PACKAGE__->register_method(