use localDate & Improve unit test (#1999)
This commit is contained in:
parent
b3a1cedc5b
commit
e00cb0ecf0
|
@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Plugins::GlobalLogout;
|
|||
use strict;
|
||||
use Mouse;
|
||||
use JSON qw(from_json to_json);
|
||||
use Time::Local;
|
||||
use Lemonldap::NG::Portal::Main::Constants qw(
|
||||
PE_OK
|
||||
PE_ERROR
|
||||
|
@ -169,7 +170,6 @@ sub activeSessions {
|
|||
my ( $self, $req ) = @_;
|
||||
my $activeSessions = [];
|
||||
my $sessions = {};
|
||||
my $regex = '^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$';
|
||||
my $user = $req->{userData}->{ $self->conf->{whatToTrace} };
|
||||
my $customParam = $self->conf->{globalLogoutCustomParam} || '';
|
||||
|
||||
|
@ -183,21 +183,29 @@ sub activeSessions {
|
|||
$user );
|
||||
|
||||
$self->logger->debug("Building array ref with sessions info...");
|
||||
@$activeSessions = sort { $b->{startTime} cmp $a->{startTime} } map { {
|
||||
@$activeSessions =
|
||||
map {
|
||||
my $epoch;
|
||||
my $regex = '^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$';
|
||||
$_->{startTime} =~ /$regex/;
|
||||
$epoch = timelocal( $6, $5, $4, $3, $2 - 1, $1 );
|
||||
$_->{startTime} = $epoch;
|
||||
if ( $_->{updateTime} ) {
|
||||
$_->{updateTime} =~ /$regex/;
|
||||
$epoch = timelocal( $6, $5, $4, $3, $2 - 1, $1 );
|
||||
$_->{updateTime} = $epoch;
|
||||
}
|
||||
$_;
|
||||
}
|
||||
sort { $b->{startTime} cmp $a->{startTime} } map { {
|
||||
id => $_,
|
||||
customParam => $sessions->{$_}->{$customParam},
|
||||
ipAddr => $sessions->{$_}->{'ipAddr'},
|
||||
authLevel => $sessions->{$_}->{'authenticationLevel'},
|
||||
startTime => $sessions->{$_}->{'_startTime'} =~
|
||||
s/$regex/$1-$2-$3 $4:$5:$6/ro,
|
||||
updateTime => (
|
||||
$sessions->{$_}->{'_updateTime'}
|
||||
? $sessions->{$_}->{'_updateTime'} =~
|
||||
s/$regex/$1-$2-$3 $4:$5:$6/ro
|
||||
: ''
|
||||
),
|
||||
ipAddr => $sessions->{$_}->{ipAddr},
|
||||
authLevel => $sessions->{$_}->{authenticationLevel},
|
||||
startTime => $sessions->{$_}->{_startTime},
|
||||
updateTime => $sessions->{$_}->{_updateTime}
|
||||
};
|
||||
} keys %$sessions;
|
||||
} keys %$sessions;
|
||||
|
||||
return $activeSessions;
|
||||
}
|
||||
|
|
|
@ -13,5 +13,8 @@ timer = () ->
|
|||
window.setTimeout timer, 1000
|
||||
|
||||
$(document).ready ->
|
||||
$(".data-epoch").each ->
|
||||
myDate = new Date($(this).text() * 1000)
|
||||
$(this).text(myDate.toLocaleString())
|
||||
window.setTimeout go, 30000
|
||||
window.setTimeout timer, 1000
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
$(".data-epoch").each(function() {
|
||||
var myDate;
|
||||
myDate = new Date($(this).text() * 1000);
|
||||
return $(this).text(myDate.toLocaleString());
|
||||
});
|
||||
window.setTimeout(go, 30000);
|
||||
return window.setTimeout(timer, 1000);
|
||||
});
|
||||
|
|
|
@ -1 +1 @@
|
|||
(function(){var t,e,n;e=30,t=function(){return $("#globallogout").submit()},n=function(){var t;return t=$("#timer").html(),0<e&&e--,t=t.replace(/\d+/,e),$("#timer").html(t),window.setTimeout(n,1e3)},$(document).ready(function(){return window.setTimeout(t,3e4),window.setTimeout(n,1e3)})}).call(this);
|
||||
(function(){var t,e,n;e=30,t=function(){return $("#globallogout").submit()},n=function(){var t;return t=$("#timer").html(),0<e&&e--,t=t.replace(/\d+/,e),$("#timer").html(t),window.setTimeout(n,1e3)},$(document).ready(function(){return $(".data-epoch").each(function(){var t;return t=new Date(1e3*$(this).text()),$(this).text(t.toLocaleString())}),window.setTimeout(t,3e4),window.setTimeout(n,1e3)})}).call(this);
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["lemonldap-ng-portal/site/htdocs/static/common/js/globalLogout.js"],"names":["go","i","timer","$","submit","h","html","replace","window","setTimeout","document","ready","call","this"],"mappings":"CACA,WACE,IAAIA,EAAIC,EAAGC,EAEXD,EAAI,GAEJD,EAAK,WACH,OAAOG,EAAE,iBAAiBC,UAG5BF,EAAQ,WACN,IAAIG,EAOJ,OANAA,EAAIF,EAAE,UAAUG,OACR,EAAJL,GACFA,IAEFI,EAAIA,EAAEE,QAAQ,MAAON,GACrBE,EAAE,UAAUG,KAAKD,GACVG,OAAOC,WAAWP,EAAO,MAGlCC,EAAEO,UAAUC,MAAM,WAEhB,OADAH,OAAOC,WAAWT,EAAI,KACfQ,OAAOC,WAAWP,EAAO,SAGjCU,KAAKC"}
|
||||
{"version":3,"sources":["lemonldap-ng-portal/site/htdocs/static/common/js/globalLogout.js"],"names":["go","i","timer","$","submit","h","html","replace","window","setTimeout","document","ready","each","myDate","Date","this","text","toLocaleString","call"],"mappings":"CACA,WACE,IAAIA,EAAIC,EAAGC,EAEXD,EAAI,GAEJD,EAAK,WACH,OAAOG,EAAE,iBAAiBC,UAG5BF,EAAQ,WACN,IAAIG,EAOJ,OANAA,EAAIF,EAAE,UAAUG,OACR,EAAJL,GACFA,IAEFI,EAAIA,EAAEE,QAAQ,MAAON,GACrBE,EAAE,UAAUG,KAAKD,GACVG,OAAOC,WAAWP,EAAO,MAGlCC,EAAEO,UAAUC,MAAM,WAOhB,OANAR,EAAE,eAAeS,KAAK,WACpB,IAAIC,EAEJ,OADAA,EAAS,IAAIC,KAAsB,IAAjBX,EAAEY,MAAMC,QACnBb,EAAEY,MAAMC,KAAKH,EAAOI,oBAE7BT,OAAOC,WAAWT,EAAI,KACfQ,OAAOC,WAAWP,EAAO,SAGjCgB,KAAKH"}
|
|
@ -22,8 +22,8 @@
|
|||
<tbody>
|
||||
<TMPL_LOOP NAME="SESSIONS">
|
||||
<tr>
|
||||
<td scope="row"><TMPL_VAR NAME="startTime"></td>
|
||||
<td scope="row"><TMPL_VAR NAME="updateTime"></td>
|
||||
<td scope="row" class="data-epoch"><TMPL_VAR NAME="startTime"></td>
|
||||
<td scope="row" class="data-epoch"><TMPL_VAR NAME="updateTime"></td>
|
||||
<td scope="row"><TMPL_VAR NAME="ipAddr"></td>
|
||||
<td scope="row"><TMPL_VAR NAME="authLevel"></td>
|
||||
<TMPL_IF NAME="CUSTOMPRM">
|
||||
|
|
|
@ -143,13 +143,18 @@ ok( $res->[2]->[0] =~ m%<td scope="row">DEMO</td>%, 'CustomParam found "DEMO"' )
|
|||
or explain( $res->[2]->[0], 'CustomParam DEMO' );
|
||||
my @c = ( $res->[2]->[0] =~ m%<td scope="row">127.0.0.1</td>%gs );
|
||||
my @d = ( $res->[2]->[0] =~ m%<th scope="col">%gs );
|
||||
my @e = ( $res->[2]->[0] =~ m%class="data-epoch">(\d{10})</td>%gs );
|
||||
|
||||
## Three entries found
|
||||
ok( @c == 3, ' -> Three entries found' )
|
||||
or explain( $res->[2]->[0], "Number of session(s) found = " . scalar @c );
|
||||
ok( @d == 5, ' -> Five <th> found' )
|
||||
or explain( $res->[2]->[0], "Number of <th> found = " . scalar @d );
|
||||
count(4);
|
||||
ok( @e == 3, ' -> Three epoch found' )
|
||||
or explain( $res->[2]->[0], "Number of epoch found = " . scalar @e );
|
||||
ok( time() - 1 <= $e[0] && $e[0] <= time() + 5, 'Right epoch found' )
|
||||
or print STDERR Dumper( $res->[2]->[0] ), time(), " / $1";
|
||||
count(6);
|
||||
|
||||
## GlobalLogout request for 'dwho'
|
||||
$query .= '&all=1';
|
||||
|
|
Loading…
Reference in New Issue
Block a user