use strict;
use Data::Dumper;
use Digest::MD5;
+use JSON;
use Maasha::Common;
use Maasha::Filesys;
# 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;
}
# 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;
}
1;
+
+__END__
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' } )
# {
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' } ) )
$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
{