Working on Choice (#595)
This commit is contained in:
parent
1577400bf4
commit
8307161f0c
|
@ -2,7 +2,7 @@ package Lemonldap::NG::Portal::Auth::Choice;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
use Lemonldap::NG::Portal::Main::Constants qw(PE_FIRSTACCESS);
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_FIRSTACCESS);
|
||||||
|
|
||||||
extends 'Lemonldap::NG::Portal::Lib::Choice';
|
extends 'Lemonldap::NG::Portal::Lib::Choice';
|
||||||
|
|
||||||
|
@ -21,17 +21,17 @@ sub authenticate {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub authForce {
|
sub authForce {
|
||||||
$_[0]->checkChoice( $_[1] );
|
$_[0]->checkChoice( $_[1] ) or return PE_OK;
|
||||||
return $_[1]->datas->{enabledMods}->[0]->authForce( $_[1] );
|
return $_[1]->datas->{enabledMods}->[0]->authForce( $_[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub authLogout {
|
sub authLogout {
|
||||||
$_[0]->checkChoice( $_[1] );
|
$_[0]->checkChoice( $_[1] ) or return PE_OK;
|
||||||
return $_[1]->datas->{enabledMods}->[0]->authLogout( $_[1] );
|
return $_[1]->datas->{enabledMods}->[0]->authLogout( $_[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getDisplayType {
|
sub getDisplayType {
|
||||||
$_[0]->checkChoice( $_[1] );
|
$_[0]->checkChoice( $_[1] ) or return PE_OK;
|
||||||
return $_[1]->datas->{enabledMods}->[0]->getDisplayType( $_[1] );
|
return $_[1]->datas->{enabledMods}->[0]->getDisplayType( $_[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,17 +34,21 @@ sub init {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# error() is set by underlying module
|
$self->lmLog("Choice: unable to load $name, disabling it: ".$self->error,'error');
|
||||||
return 0;
|
$self->error('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unless( keys %{$self->modules}) {
|
||||||
|
$self->error('Choice: no available modules found, aborting');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub checkChoice {
|
sub checkChoice {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
return $req->sessionInfo->{_choice} if ( $req->sessionInfo->{_choice} );
|
my $name = $req->sessionInfo->{_choice} || $req->param( $self->conf->{authChoiceParam} ) or return 0;
|
||||||
my $name = $req->param( $self->conf->{authChoiceParam} ) or return 0;
|
return $name if ( $req->datas->{enabledMods} );
|
||||||
unless ( defined $self->modules->{$name} ) {
|
unless ( defined $self->modules->{$name} ) {
|
||||||
$self->lmLog( "Unknown choice '$name'", 'error' );
|
$self->lmLog( "Unknown choice '$name'", 'error' );
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -52,11 +56,14 @@ sub checkChoice {
|
||||||
$req->sessionInfo->{_choice} = $name;
|
$req->sessionInfo->{_choice} = $name;
|
||||||
$req->datas->{enabledMods} = [ $self->modules->{$name} ];
|
$req->datas->{enabledMods} = [ $self->modules->{$name} ];
|
||||||
$self->p->_authentication->authnLevel("${name}AuthnLevel");
|
$self->p->_authentication->authnLevel("${name}AuthnLevel");
|
||||||
return 1;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub name {
|
sub name {
|
||||||
my ( $self, $req, $type ) = @_;
|
my ( $self, $req, $type ) = @_;
|
||||||
|
unless($req) {
|
||||||
|
return 'Choice';
|
||||||
|
}
|
||||||
my $n = ref( $req->datas->{enableMods}->[0] );
|
my $n = ref( $req->datas->{enableMods}->[0] );
|
||||||
$n =~ s/^Lemonldap::NG::Portal::(?:(?:UserDB|Auth)::)?//;
|
$n =~ s/^Lemonldap::NG::Portal::(?:(?:UserDB|Auth)::)?//;
|
||||||
return $n;
|
return $n;
|
||||||
|
|
|
@ -268,7 +268,7 @@ sub display {
|
||||||
# Choose what form to display if not in a loop
|
# Choose what form to display if not in a loop
|
||||||
else {
|
else {
|
||||||
|
|
||||||
my $displayType = $self->_authentication->getDisplayType();
|
my $displayType = $self->_authentication->getDisplayType($req);
|
||||||
|
|
||||||
$self->lmLog( "Display type $displayType ", 'debug' );
|
$self->lmLog( "Display type $displayType ", 'debug' );
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ sub checkLogout {
|
||||||
|
|
||||||
sub authLogout {
|
sub authLogout {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
return $self->_authentication->authLogout(@_);
|
return $self->_authentication->authLogout($req);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub deleteSession {
|
sub deleteSession {
|
||||||
|
@ -432,7 +432,7 @@ sub cookie {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _dump {
|
sub _dump {
|
||||||
my($self, $variable) = @_;
|
my ( $self, $variable ) = @_;
|
||||||
require Data::Dumper;
|
require Data::Dumper;
|
||||||
$Data::Dumper::Indent = 0;
|
$Data::Dumper::Indent = 0;
|
||||||
$self->lmLog( "Dump: " . Data::Dumper::Dumper($variable), 'debug' );
|
$self->lmLog( "Dump: " . Data::Dumper::Dumper($variable), 'debug' );
|
||||||
|
|
|
@ -105,7 +105,7 @@ sub error_type {
|
||||||
|
|
||||||
sub init {
|
sub init {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
$self->{$_} = {} foreach(qw(datas customParameters));;
|
$self->{$_} = {} foreach(qw(datas customParameters sessionInfo));;
|
||||||
$self->{$_} = [] foreach(qw(respCookies));;
|
$self->{$_} = [] foreach(qw(respCookies));;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,8 +164,8 @@ sub getModule {
|
||||||
}->{$type}
|
}->{$type}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ( $self->$mod->can('name') ) {
|
if ( my $sub = $self->$mod->can('name') ) {
|
||||||
return $self->$mod->can('name')->($self->mod,$req,$type);
|
return $sub->( $self->$mod, $req, $type );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $s = ref( $self->$mod );
|
my $s = ref( $self->$mod );
|
||||||
|
|
|
@ -21,7 +21,6 @@ sub init {
|
||||||
|
|
||||||
unless ( $self->p->getModule( undef, 'auth' ) =~ /Demo/ ) {
|
unless ( $self->p->getModule( undef, 'auth' ) =~ /Demo/ ) {
|
||||||
$self->p->error("Use UserDB::Demo only with Auth::Demo");
|
$self->p->error("Use UserDB::Demo only with Auth::Demo");
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sample accounts from Doctor Who characters
|
# Sample accounts from Doctor Who characters
|
||||||
|
|
Loading…
Reference in New Issue
Block a user