]> git.donarmstrong.com Git - biopieces.git/commitdiff
changed BGB session format to JSON
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sat, 13 Mar 2010 17:13:48 +0000 (17:13 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sat, 13 Mar 2010 17:13:48 +0000 (17:13 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@898 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/BGB/Session.pm
www/index.cgi

index 129e41fd8d0a91f9dc676da7002021948ef439cd..d55132a1dd113227e589c9ba2e2cdfcb2a047f6b 100644 (file)
@@ -32,6 +32,7 @@ use warnings;
 use strict;
 use Data::Dumper;
 use Digest::MD5;
+use JSON;
 use Maasha::Common;
 use Maasha::Filesys;
 
@@ -72,26 +73,21 @@ sub session_restore
 
     # Returns a hashref.
 
-    my ( $fh, $line, $user, $password, $sid, $time, %session );
+    my ( $fh, $json, $json_text, $session );
+
+    local $/ = undef;
 
     $fh = Maasha::Filesys::file_read_open( $file );
 
-    while ( $line = <$fh> )
-    {
-        chomp $line;
+    $json_text = <$fh>;
 
-        ( $user, $password, $sid, $time ) = split /\t/, $line;
+    close $fh;
 
-        $session{ $user } = {
-            PASSWORD   => $password,
-            SESSION_ID => $sid,
-            TIME       => $time,
-        };
-    }
+    $json = new JSON;
 
-    close $fh;
+    $session = $json->decode( $json_text );
 
-    return wantarray ? %session : \%session;
+    return wantarray ? %{ $session } : $session;
 }
 
 
@@ -107,20 +103,15 @@ sub session_store
 
     # Returns nothing.
 
-    my ( $fh, $user );
+    my ( $json, $json_text, $fh );
+
+    $json = new JSON;
+
+    $json_text = $json->pretty->encode( $session );
 
     $fh = Maasha::Filesys::file_write_open( $file );
 
-    foreach $user ( keys %{ $session } )
-    {
-        print $fh join(
-            "\t",
-            $user,
-            $session->{ $user }->{ 'PASSWORD' },
-            $session->{ $user }->{ 'SESSION_ID' },
-            $session->{ $user }->{ 'TIME' }
-        ), "\n";
-    }
+    print $fh $json_text;
 
     close $fh;
 }
@@ -130,3 +121,5 @@ sub session_store
 
 
 1;
+
+__END__
index ec03bf65bfd2322c54aad064ac8393c46b08ef34..8a3377f0248fdfcc9b35bb7fde3905e0e2551f84 100755 (executable)
@@ -202,7 +202,7 @@ sub cookie_session
 
     my ( $session );
 
-    $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+    $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.json" );
 
     # if ( $cookie->{ 'SESSION_ID' } )
     # {
@@ -252,7 +252,7 @@ sub cookie_login
 
     if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
     {
-        $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+        $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.json" );
     
         if ( exists $session->{ $cookie->{ 'USER' } } and
              $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
@@ -264,7 +264,7 @@ sub cookie_login
             $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
             $cookie->{ 'LOGIN' }      = "OK";
 
-            Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
+            Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.json", $session );
         }
         else
         {