Improve code (#1386)

This commit is contained in:
Christophe Maudoux 2019-04-26 23:00:17 +02:00
parent 441df6e7ea
commit 548032fbe0
3 changed files with 27 additions and 26 deletions

View File

@ -295,24 +295,24 @@ sub run {
return $self->p->sendError( $req, "Corrupted session", 500 );
}
}
else {
$self->logger->debug("No 2F Device found");
$_2fDevices = [];
}
# Delete TOTP 2F device
my @keep = ();
while (@$_2fDevices) {
my $element = shift @$_2fDevices;
$self->logger->debug("Looking for 2F device to delete ...");
push @keep, $element unless ( $element->{epoch} eq $epoch );
}
# my @keep = ();
# while (@$_2fDevices) {
# my $element = shift @$_2fDevices;
# $self->logger->debug("Looking for 2F device to delete ...");
# push @keep, $element unless ( $element->{epoch} eq $epoch );
# }
# Delete TOTP 2F device
@$_2fDevices = grep { $_->{epoch} ne $epoch } @$_2fDevices;
$self->logger->debug(
"Delete 2F Device : { type => 'TOTP', epoch => $epoch }");
$self->p->updatePersistentSession( $req,
{ _2fDevices => to_json( \@keep ) } );
{ _2fDevices => to_json( $_2fDevices ) } );
$self->userLogger->notice('TOTP deletion succeed');
return [
200,

View File

@ -287,17 +287,19 @@ sub run {
$_2fDevices = [];
}
my @keep = ();
while (@$_2fDevices) {
my $element = shift @$_2fDevices;
$self->logger->debug("Looking for 2F device to delete ...");
push @keep, $element unless ( $element->{epoch} eq $epoch );
}
# my @keep = ();
# while (@$_2fDevices) {
# my $element = shift @$_2fDevices;
# $self->logger->debug("Looking for 2F device to delete ...");
# push @keep, $element unless ( $element->{epoch} eq $epoch );
# }
# Delete U2F device
@$_2fDevices = grep { $_->{epoch} ne $epoch } @$_2fDevices;
$self->logger->debug(
"Delete 2F Device : { type => 'U2F', epoch => $epoch }");
$self->p->updatePersistentSession( $req,
{ _2fDevices => to_json( \@keep ) } );
{ _2fDevices => to_json( $_2fDevices ) } );
$self->userLogger->notice('U2F key unregistration succeed');
return [
200,

View File

@ -176,31 +176,30 @@ sub run {
return $self->p->sendError( $req, "Corrupted session", 500 );
}
}
else {
$self->logger->debug("No 2F Device found");
$_2fDevices = [];
}
my @keep = ();
while (@$_2fDevices) {
my $element = shift @$_2fDevices;
$self->logger->debug("Looking for 2F device to delete ...");
push @keep, $element unless ( $element->{epoch} eq $epoch );
}
# my @keep = ();
# while (@$_2fDevices) {
# my $element = shift @$_2fDevices;
# $self->logger->debug("Looking for 2F device to delete ...");
# push @keep, $element unless ( $element->{epoch} eq $epoch );
# }
# Delete Yubikey device
@$_2fDevices = grep { $_->{epoch} ne $epoch } @$_2fDevices;
$self->logger->debug(
"Delete 2F Device : { type => 'UBK', epoch => $epoch }");
$self->p->updatePersistentSession( $req,
{ _2fDevices => to_json( \@keep ) } );
{ _2fDevices => to_json( $_2fDevices ) } );
$self->userLogger->notice('Yubikey deletion succeed');
return [
200,
[ 'Content-Type' => 'application/json', 'Content-Length' => 12, ],
['{"result":1}']
];
}
else {
$self->logger->error("Unknown Yubikey action -> $action");