From ec46fe01e543b8aefb6d2a34a1f0b30171dc9ffb Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Sat, 2 Jul 2016 19:09:45 +0000 Subject: [PATCH] Working on Choice (#595) --- .../lib/Lemonldap/NG/Portal/Auth/Choice.pm | 10 ++--- .../lib/Lemonldap/NG/Portal/Lib/Choice.pm | 45 ++++++++++++------- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 4 +- .../lib/Lemonldap/NG/Portal/UserDB/Choice.pm | 6 +-- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm index a14c800e0..7ec3b8cab 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/Choice.pm @@ -13,26 +13,26 @@ sub init { sub extractFormInfo { my ( $self, $req ) = @_; $self->checkChoice($req) or return PE_FIRSTACCESS; - return $req->datas->{enabledMods}->[0]->extractFormInfo($req); + return $req->datas->{enabledMods0}->[0]->extractFormInfo($req); } sub authenticate { - return $_[1]->datas->{enabledMods}->[0]->authenticate( $_[1] ); + return $_[1]->datas->{enabledMods0}->[0]->authenticate( $_[1] ); } sub authForce { $_[0]->checkChoice( $_[1] ) or return PE_OK; - return $_[1]->datas->{enabledMods}->[0]->authForce( $_[1] ); + return $_[1]->datas->{enabledMods0}->[0]->authForce( $_[1] ); } sub authLogout { $_[0]->checkChoice( $_[1] ) or return PE_OK; - return $_[1]->datas->{enabledMods}->[0]->authLogout( $_[1] ); + return $_[1]->datas->{enabledMods0}->[0]->authLogout( $_[1] ); } sub getDisplayType { $_[0]->checkChoice( $_[1] ) or return PE_OK; - return $_[1]->datas->{enabledMods}->[0]->getDisplayType( $_[1] ); + return $_[1]->datas->{enabledMods0}->[0]->getDisplayType( $_[1] ); } 1; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm index 3ed5d5bb4..329877779 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Choice.pm @@ -9,6 +9,8 @@ our $VERSION = '2.0.0'; has modules => ( is => 'rw', default => sub { {} } ); +has type => ( is => 'rw' ); + # INITIALIZATION # init() must be called by module::init() with a number: @@ -17,6 +19,7 @@ has modules => ( is => 'rw', default => sub { {} } ); # - 2 for passwordDB ? sub init { my ( $self, $type ) = @_; + $self->type($type); foreach my $name ( keys %{ $self->conf->{authChoiceModules} } ) { my @mods = @@ -34,11 +37,13 @@ sub init { ); } else { - $self->lmLog("Choice: unable to load $name, disabling it: ".$self->error,'error'); + $self->lmLog( + "Choice: unable to load $name, disabling it: " . $self->error, + 'error' ); $self->error(''); } } - unless( keys %{$self->modules}) { + unless ( keys %{ $self->modules } ) { $self->error('Choice: no available modules found, aborting'); return 0; } @@ -47,21 +52,24 @@ sub init { sub checkChoice { my ( $self, $req ) = @_; - my $name = $req->sessionInfo->{_choice} || $req->param( $self->conf->{authChoiceParam} ) or return 0; - return $name if ( $req->datas->{enabledMods} ); + my $name = + $req->sessionInfo->{_choice} + || $req->param( $self->conf->{authChoiceParam} ) + or return 0; + return $name if ( $req->datas->{ "enabledMods" . $self->type } ); unless ( defined $self->modules->{$name} ) { $self->lmLog( "Unknown choice '$name'", 'error' ); return 0; } $req->sessionInfo->{_choice} = $name; - $req->datas->{enabledMods} = [ $self->modules->{$name} ]; + $req->datas->{ "enabledMods" . $self->type } = [ $self->modules->{$name} ]; $self->p->_authentication->authnLevel("${name}AuthnLevel"); return $name; } sub name { my ( $self, $req, $type ) = @_; - unless($req) { + unless ($req) { return 'Choice'; } my $n = ref( $req->datas->{enableMods}->[0] ); @@ -69,7 +77,7 @@ sub name { return $n; } -package Lemonldap::NG::Portal::Simple; +package Lemonldap::NG::Portal::Main; # Build authentication loop displayed in template # Return authLoop array reference @@ -113,20 +121,25 @@ sub _buildAuthLoop { { name => $name, key => $_, module => $auth, url => $url }; # Get displayType for this module - my $displayType = - &{"Lemonldap::NG::Portal::Auth::${auth}::getDisplayType"}; + no strict 'refs'; + my $displayType = "Lemonldap::NG::Portal::Auth::${auth}" + ->can('getDisplayType')->( undef, $req ); $self->lmLog( "Display type $displayType for module $auth", 'debug' ); $optionsLoop->{$displayType} = 1; - # If displayType is logo, check if key.png is available - if ( - -e $self->getApacheHtdocsPath . "/skins/common/" . $_ . ".png" ) - { - $optionsLoop->{logoFile} = $_ . ".png"; - } - else { $optionsLoop->{logoFile} = $auth . ".png"; } + # If displayType is logo, check if key.png is available + # TODO: + #if ( + # -e $self->getApacheHtdocsPath . "/skins/common/" . $_ . ".png" ) + #{ + # $optionsLoop->{logoFile} = $_ . ".png"; + #} + #else { + $optionsLoop->{logoFile} = $auth . ".png"; + + #} # Register item in loop push @authLoop, $optionsLoop; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm index f3168361c..84745f28b 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -253,10 +253,10 @@ sub display { else { # Authentication loop - if ( $self->{authLoop} ) { + if ( my $authLoop = $self->_buildAuthLoop($req) ) { %templateParams = ( %templateParams, - AUTH_LOOP => $self->conf->{authLoop}, + AUTH_LOOP => $authLoop, CHOICE_PARAM => $self->conf->{authChoiceParam}, CHOICE_VALUE => $req->{_authChoice}, DISPLAY_FORM => 0, diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm index 495136993..b68fd74b4 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDB/Choice.pm @@ -17,16 +17,16 @@ sub init { sub getUser { my ( $self, $req ) = @_; $self->checkChoice($req) or return PE_FIRSTACCESS; - return $req->datas->{enabledMods}->[0]->getUser($req); + return $req->datas->{enabledMods1}->[0]->getUser($req); } sub setSessionInfo { - return $_[1]->datas->{enabledMods}->[0]->setSessionInfo( $_[1] ); + return $_[1]->datas->{enabledMods1}->[0]->setSessionInfo( $_[1] ); } sub setGroups { $_[0]->checkChoice( $_[1] ); - return $_[1]->datas->{enabledMods}->[0]->setGroups( $_[1] ); + return $_[1]->datas->{enabledMods1}->[0]->setGroups( $_[1] ); } 1;