|
|
|
@ -19,7 +19,6 @@ use Lemonldap::NG::Portal::Main::Constants qw( |
|
|
|
|
PE_OK |
|
|
|
|
PE_SENDRESPONSE |
|
|
|
|
PE_TOKENEXPIRED |
|
|
|
|
PE_INFO |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
our $VERSION = '2.0.5'; |
|
|
|
@ -31,7 +30,7 @@ extends 'Lemonldap::NG::Portal::Main::Plugin'; |
|
|
|
|
has sfModules => ( is => 'rw', default => sub { [] } ); |
|
|
|
|
has sfRModules => ( is => 'rw', default => sub { [] } ); |
|
|
|
|
has sfReq => ( is => 'rw' ); |
|
|
|
|
has sfRule => ( is => 'rw' ); |
|
|
|
|
has sfMsgRule => ( is => 'rw' ); |
|
|
|
|
|
|
|
|
|
has ott => ( |
|
|
|
|
is => 'rw', |
|
|
|
@ -108,7 +107,7 @@ sub init { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unless ( |
|
|
|
|
$self->sfRule( |
|
|
|
|
$self->sfMsgRule( |
|
|
|
|
$self->p->HANDLER->buildSub( |
|
|
|
|
$self->p->HANDLER->substitute( |
|
|
|
|
$self->conf->{sfRemovedMsgRule} |
|
|
|
@ -202,19 +201,27 @@ sub run { |
|
|
|
|
$self->p->updatePersistentSession( $req, |
|
|
|
|
{ _2fDevices => to_json($_2fDevices) } ); |
|
|
|
|
|
|
|
|
|
# Display notification or message if required |
|
|
|
|
my $res = 0; |
|
|
|
|
if ( $self->sfRule->( $req, $req->sessionInfo ) ) { |
|
|
|
|
my $notifEngine = $self->p->loadedModules->{ |
|
|
|
|
'Lemonldap::NG::Portal::Plugins::Notifications'}; |
|
|
|
|
if ( $notifEngine && $self->conf->{sfRemovedUseNotif} ) { |
|
|
|
|
$self->logger->debug("Notifications plugin enabled"); |
|
|
|
|
$res = |
|
|
|
|
$self->_sendNotification( $req, $notifEngine, $removed ); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$res = $self->_sendInfo( $req, $removed ); |
|
|
|
|
} |
|
|
|
|
# Display message if required |
|
|
|
|
if ( $self->sfMsgRule->( $req, $req->sessionInfo ) ) { |
|
|
|
|
my $uid = $req->user; |
|
|
|
|
my $date = strftime "%Y-%m-%d", localtime; |
|
|
|
|
my $ref = $self->conf->{sfRemovedNotifRef} || 'RemoveSF'; |
|
|
|
|
my $title = $self->conf->{sfRemovedNotifTitle} |
|
|
|
|
|| 'Second factor notification'; |
|
|
|
|
my $msg = $self->conf->{sfRemovedNotifMsg} |
|
|
|
|
|| "$removed expired second factor(s) has/have been removed!"; |
|
|
|
|
$msg =~ s/_removedSF_/$removed/; |
|
|
|
|
|
|
|
|
|
my $params = |
|
|
|
|
$removed > 1 |
|
|
|
|
? { trspan => "expired2Fremoved, $removed" } |
|
|
|
|
: { trspan => "oneExpired2Fremoved" }; |
|
|
|
|
|
|
|
|
|
my $res = |
|
|
|
|
$self->conf->{sfRemovedUseNotif} |
|
|
|
|
? $self->createNotification( $req, $uid, $date, $ref, $title, |
|
|
|
|
$msg ) |
|
|
|
|
: $self->displayTemplate( $req, 'simpleInfo', $params ); |
|
|
|
|
return $res if $res; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -494,57 +501,4 @@ sub restoreSession { |
|
|
|
|
: $self->_displayRegister( $req, @path ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub _sendInfo { |
|
|
|
|
my ( $self, $req, $removed ) = @_; |
|
|
|
|
$self->logger->debug("Return simpleInfo template"); |
|
|
|
|
$req->info( |
|
|
|
|
$self->loadTemplate( |
|
|
|
|
'simpleInfo', |
|
|
|
|
( |
|
|
|
|
$removed > 1 |
|
|
|
|
? ( |
|
|
|
|
params => { |
|
|
|
|
trspan => "expired2Fremoved, $removed" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
: ( params => { trspan => "oneExpired2Fremoved" } ) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
return PE_INFO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub _sendNotification { |
|
|
|
|
my ( $self, $req, $notifEngine, $removed ) = @_; |
|
|
|
|
my $uid = $req->user; |
|
|
|
|
my $date = strftime "%Y-%m-%d", localtime; |
|
|
|
|
my $ref = $self->conf->{sfRemovedNotifRef} || 'RemoveSF'; |
|
|
|
|
my $title = |
|
|
|
|
$self->conf->{sfRemovedNotifTitle} || 'Second factor notification'; |
|
|
|
|
my $msg = $self->conf->{sfRemovedNotifMsg} |
|
|
|
|
|| "$removed expired second factor(s) has/have been removed!"; |
|
|
|
|
$msg =~ s/_removedSF_/$removed/; |
|
|
|
|
|
|
|
|
|
# Prepare notification |
|
|
|
|
my $content = |
|
|
|
|
$self->conf->{oldNotifFormat} |
|
|
|
|
? '<?xml version="1.0" encoding="UTF-8"?><root><notification uid="_uid_" date="_date_" reference="_ref_"><title>_title_</title><text>_msg_</text></notification></root>' |
|
|
|
|
: '[{"uid":"_uid_","date":"_date_","title":"_title_","reference":"_ref_","text":"_msg_"}]'; |
|
|
|
|
$content =~ s/_uid_/$uid/; |
|
|
|
|
$content =~ s/_ref_/$ref/; |
|
|
|
|
$content =~ s/_date_/$date/; |
|
|
|
|
$content =~ s/_title_/$title/; |
|
|
|
|
$content =~ s/_msg_/$msg/; |
|
|
|
|
|
|
|
|
|
if ( $notifEngine->module->notifObject->newNotification($content) ) { |
|
|
|
|
$self->logger->debug("Notification SF successfully appended"); |
|
|
|
|
$self->userLogger->notice("Notification SF successfully appended"); |
|
|
|
|
return PE_OK; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$self->logger->debug("Notification NOT created!"); |
|
|
|
|
return $self->_sendInfo( $req, $removed ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
1; |
|
|
|
|