diff --git a/fastcgi-server/man/llng-fastcgi-server.1p b/fastcgi-server/man/llng-fastcgi-server.1p index 24d457c93..1067caacf 100644 --- a/fastcgi-server/man/llng-fastcgi-server.1p +++ b/fastcgi-server/man/llng-fastcgi-server.1p @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "llng-fastcgi-server 1" -.TH llng-fastcgi-server 1 "2016-03-08" "perl v5.22.1" "User Contributed Perl Documentation" +.TH llng-fastcgi-server 1 "2016-05-31" "perl v5.22.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm index ffd60c12f..c698b86b3 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm @@ -124,8 +124,7 @@ sub init { sub checkNotifDuringAuth { my ( $self, $req ) = @_; - if ( $req->{datas}->{notification} = $self->checkForNotifications($req) ) - { + if ( $req->{datas}->{notification} = $self->checkForNotifications($req) ) { $self->rebuildCookies($req); # Restore and cipher cookies @@ -228,7 +227,7 @@ sub getNotifBack { # Search for Lemonldap::NG cookie (ciphered) my $id; - unless ( $id = $req->cookies + unless ($id = $req->cookies and $id =~ s/$self->{conf}->{cookieName}=([^,; ]+)/$1/o ) { return $self->p->sendError( $req, 'No cookie found', 401 ); @@ -248,48 +247,60 @@ sub getNotifBack { # Get accepted notifications $req->parseBody; - my ( $refs, $checks ); + my ( $refs, $checks ) = ( {}, {} ); my $prms = $req->params; foreach ( keys %$prms ) { my $v = $prms->{$_}; if (s/^reference//) { - $refs->{$_} = $v; + $refs->{$v} = $_; } - elsif ( s/^check// and /^(\d+x\d+)x(\d+)$/ ) { + elsif ( s/^check// and /^(\d+x\d+)x(\d+)$/ and $v eq 'accepted' ) { push @{ $checks->{$1} }, $2; } } + foreach my $file ( values %$notifs ) { my $xml = $self->parser->parse_string($file); + + # Get pending notifications and verify that they have been accepted foreach my $notif ( $xml->documentElement->getElementsByTagName('notification') ) { my $reference = $notif->getAttribute('reference'); - if ( defined $refs->{$reference} ) { - #if ( defined $XX ) { + # Check if this pending notification has been seen + if ( my $refId = $refs->{$reference} ) { - # # Verity that checkboxes have been checked - #} - #else { - # # TODO: Do the job - # delete $refs->{$reference}; - #} + # Verity that checkboxes have been checked + my @toCheck = $notif->getElementsByTagName('check'); + if ( my $toCheckCount = @toCheck ) { + unless ($checks->{$refId} + and $toCheckCount == @{ $checks->{$refId} } ) + { + return $self->p->do( $req, $self->p->afterDatas ); + } + } } else { - # TODO: launch checkForUnauthUser() + # One pending notification has been found and not accepted, + # restart process to display pending notifications + # TODO: is it a good idea to launch all 'afterDatas' subs ? + return $self->p->do( $req, $self->p->afterDatas ); } } } + + # All pending notifications has been accepted, restore cookies and launch + # 'controlUrl' to restore "urldc" using do() + $self->rebuildCookies($req); + $self->p->do( $req, ['controlUrl'] ); } else { - # TODO: redirect to portal + # No notifications checked here, this entry point must not be called. + # Redirecting to portal + $req->mustRedirect(1); + $self->p->do( $req, [] ); } - - # Else uncipher cookie, restore args and launch autoredirect - # TODO - $self->rebuildCookies($req); - $self->p->do( $req, [] ); } sub getNotifications { diff --git a/lemonldap-ng-portal/t/10-Notifications.t b/lemonldap-ng-portal/t/10-Notifications.t index 16bae5b39..9849828ab 100644 --- a/lemonldap-ng-portal/t/10-Notifications.t +++ b/lemonldap-ng-portal/t/10-Notifications.t @@ -19,7 +19,7 @@ close F; init( { - logLevel => 'debug', + logLevel => 'error', useSafeJail => 1, notifications => 1, templatesDir => 'site/templates/', @@ -63,7 +63,7 @@ ok( $res->[0] == 401, "Session isn't valid" ) count(2); # Try to validate notification without accepting it -my $str = 'reference1x1=testref'; +my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='; ok( $res = &client->_post( '/notifback', @@ -78,7 +78,23 @@ ok( $res->[0] == 200, "Don't receive redirection" ) or explain( [ $res->[0], $res->[1] ], 200 ); count(2); -print STDERR Dumper($res); +# Try to validate notification +my $str = 'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='; +ok( + $res = &client->_post( + '/notifback', + IO::String->new($str), + cookie => "lemonldap=$id", + accept => 'text/html', + length => length($str), + ), + "Accept notification" +); +ok( $res->[0] == 302, "Get redirection" ) + or explain( [ $res->[0], $res->[1] ], 302 ); +count(2); + +#print STDERR Dumper($res); clean_sessions();