Notification is displayed (#595)
This commit is contained in:
parent
04846adaa5
commit
bdace9151f
|
@ -95,7 +95,7 @@ sub display {
|
||||||
|
|
||||||
# 2.1 A notification has to be done (session is created but hidden and unusable
|
# 2.1 A notification has to be done (session is created but hidden and unusable
|
||||||
# until the user has accept the message)
|
# until the user has accept the message)
|
||||||
elsif ( my $notif = $req->{notification} ) {
|
elsif ( my $notif = $req->datas->{notification} ) {
|
||||||
$skinfile = 'notification';
|
$skinfile = 'notification';
|
||||||
%templateParams = (
|
%templateParams = (
|
||||||
AUTH_ERROR_TYPE => $req->error_type,
|
AUTH_ERROR_TYPE => $req->error_type,
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
# Notifications plugin.
|
# Notifications plugin.
|
||||||
#
|
#
|
||||||
# Three entry points for notifications:
|
# Two entry points for notifications:
|
||||||
# * a new route "/notifback" for checking accepted notifications
|
# * a new route "/notifback" for checking accepted notifications
|
||||||
# (sub getNotifBack). It launch then autoRedirect() with "mustRedirect"
|
# (sub getNotifBack). It launch then autoRedirect() with "mustRedirect"
|
||||||
# set to 1 because underlying handler has not seen user as authenticated
|
# set to 1 because underlying handler has not seen user as authenticated
|
||||||
# so datas are not set;
|
# so datas are not set;
|
||||||
# * two callbacks inserted in process steps:
|
# * a callback inserted in process steps after authentication process,
|
||||||
# - one inserted after authentication process,
|
# This callback launches checkForNotifications to get notification and
|
||||||
# - one for authenticated users,
|
# cipher LemonLDAP::NG cookies.
|
||||||
# These callbacks launch checkForNotifications to get notification and
|
|
||||||
# cipher LemonLDAP::NG cookies if any found.
|
|
||||||
|
|
||||||
package Lemonldap::NG::Portal::Plugins::Notifications;
|
package Lemonldap::NG::Portal::Plugins::Notifications;
|
||||||
|
|
||||||
|
@ -71,8 +69,6 @@ has notifField => (
|
||||||
# Declare additional process steps
|
# Declare additional process steps
|
||||||
sub afterDatas { 'checkNotifDuringAuth' }
|
sub afterDatas { 'checkNotifDuringAuth' }
|
||||||
|
|
||||||
sub forAuthUser { 'checkNotifForAuthUser' }
|
|
||||||
|
|
||||||
# Plugin initialization
|
# Plugin initialization
|
||||||
sub init {
|
sub init {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
@ -111,21 +107,26 @@ sub init {
|
||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# For now, notifications are done only during authentication process
|
||||||
|
#sub forAuthUser { 'checkNotifForAuthUser' }
|
||||||
|
|
||||||
|
#sub checkNotifForAuthUser {
|
||||||
|
# my ( $self, $req ) = @_;
|
||||||
|
# if ( my $notif = $self->checkForNotifications($req) ) {
|
||||||
|
#
|
||||||
|
# # Cipher cookies
|
||||||
|
# return PE_NOTIFICATION;
|
||||||
|
# }
|
||||||
|
# else {
|
||||||
|
# return PE_OK;
|
||||||
|
# }
|
||||||
|
#}
|
||||||
|
|
||||||
sub checkNotifDuringAuth {
|
sub checkNotifDuringAuth {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
if ( my $notif = $self->checkForNotifications($req) ) {
|
if ( $req->{datas}->{notification} = $self->checkForNotifications($req) )
|
||||||
|
{
|
||||||
# Cipher cookies
|
$self->rebuildCookies($req);
|
||||||
return PE_NOTIFICATION;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return PE_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub checkNotifForAuthUser {
|
|
||||||
my ( $self, $req ) = @_;
|
|
||||||
if ( my $notif = $self->checkForNotifications($req) ) {
|
|
||||||
|
|
||||||
# Restore and cipher cookies
|
# Restore and cipher cookies
|
||||||
return PE_NOTIFICATION;
|
return PE_NOTIFICATION;
|
||||||
|
@ -215,6 +216,7 @@ sub checkForNotifications {
|
||||||
return 0 unless $i;
|
return 0 unless $i;
|
||||||
|
|
||||||
# Returns HTML fragment
|
# Returns HTML fragment
|
||||||
|
$req->id( $self->p->HANDLER->tsv->{cipher}->encrypt( $req->id ) );
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +233,7 @@ sub getNotifBack {
|
||||||
{
|
{
|
||||||
return $self->p->sendError( 'No cookie found', 401 );
|
return $self->p->sendError( 'No cookie found', 401 );
|
||||||
}
|
}
|
||||||
$id = $self->p->conf->decrypt($id)
|
$id = $self->p->HANDLER->tsv->{cipher}->decrypt($id)
|
||||||
or return $self->sendError( 'Unable to decrypt', 500 );
|
or return $self->sendError( 'Unable to decrypt', 500 );
|
||||||
|
|
||||||
# Verify that session exists
|
# Verify that session exists
|
||||||
|
@ -286,6 +288,7 @@ sub getNotifBack {
|
||||||
|
|
||||||
# Else uncipher cookie, restore args and launch autoredirect
|
# Else uncipher cookie, restore args and launch autoredirect
|
||||||
# TODO
|
# TODO
|
||||||
|
$self->rebuildCookies($req);
|
||||||
$self->p->do( $req, [] );
|
$self->p->do( $req, [] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,4 +304,14 @@ sub getNotifications {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub rebuildCookies {
|
||||||
|
my ( $self, $req ) = @_;
|
||||||
|
my @tmp;
|
||||||
|
for ( my $i = 0 ; $i < @{ $req->{respHeaders} } ; $i += 2 ) {
|
||||||
|
push @tmp, $req->respHeaders->[0], $req->respHeaders->[1]
|
||||||
|
unless ( $req->respHeaders eq 'Set-Cookie' );
|
||||||
|
}
|
||||||
|
$self->p->buildCookie($req);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
58
lemonldap-ng-portal/t/10-Notifications.t
Normal file
58
lemonldap-ng-portal/t/10-Notifications.t
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
use IO::String;
|
||||||
|
|
||||||
|
require 't/test-lib.pm';
|
||||||
|
|
||||||
|
my $res;
|
||||||
|
my $file = 't/20160530_dwho_dGVzdHJlZg==.xml';
|
||||||
|
|
||||||
|
open F, "> $file" or die($!);
|
||||||
|
print F '<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root><notification uid="dwho" date="2016-05-30" reference="testref"><root>
|
||||||
|
<title>Test title</title>
|
||||||
|
<subtitle>Test subtitle</subtitle>
|
||||||
|
<text>This is a test text</text>
|
||||||
|
<check>Accept test</check>
|
||||||
|
</root></notification></root>';
|
||||||
|
close F;
|
||||||
|
|
||||||
|
init(
|
||||||
|
{
|
||||||
|
logLevel => 'error',
|
||||||
|
useSafeJail => 1,
|
||||||
|
notifications => 1,
|
||||||
|
templatesDir => 'site/templates/',
|
||||||
|
notificationStorage => 'File',
|
||||||
|
notificationStorageOptions => {
|
||||||
|
dirName => 't'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
# Try yo authenticate
|
||||||
|
# -------------------
|
||||||
|
ok(
|
||||||
|
$res = &client->_post(
|
||||||
|
'/',
|
||||||
|
IO::String->new(
|
||||||
|
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
|
||||||
|
accept => 'text/html',
|
||||||
|
length => 64,
|
||||||
|
),
|
||||||
|
'Auth query'
|
||||||
|
);
|
||||||
|
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
|
||||||
|
my $cookies = getCookies($res);
|
||||||
|
my $id;
|
||||||
|
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
|
||||||
|
or explain( $res, 'Set-Cookie: something' );
|
||||||
|
count(3);
|
||||||
|
|
||||||
|
#print STDERR Dumper($res);
|
||||||
|
|
||||||
|
clean_sessions();
|
||||||
|
|
||||||
|
unlink $file;
|
||||||
|
|
||||||
|
done_testing( count() );
|
Loading…
Reference in New Issue
Block a user