Override logo and label in 2fregisters template (#2690)

This commit is contained in:
Clément OUDOT 2022-07-06 19:55:28 +02:00
parent 0fffe97e99
commit 4896e5de64
8 changed files with 53 additions and 26 deletions

View File

@ -9,6 +9,7 @@ lib/Lemonldap/NG/Portal/2F/Engines/Default.pm
lib/Lemonldap/NG/Portal/2F/Ext2F.pm
lib/Lemonldap/NG/Portal/2F/Mail2F.pm
lib/Lemonldap/NG/Portal/2F/Radius.pm
lib/Lemonldap/NG/Portal/2F/Register/Base.pm
lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm
lib/Lemonldap/NG/Portal/2F/Register/U2F.pm
lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm
@ -792,6 +793,7 @@ t/71-2F-U2F-with-History.t
t/71-2F-U2F-with-TTL-and-msg.t
t/71-2F-U2F-with-TTL.t
t/71-2F-U2F.t
t/72-2F-REST-CodeActivation-Resend.t
t/72-2F-REST-with-History.t
t/73-2F-UTOTP-TOTP-and-U2F-with-History.t
t/73-2F-UTOTP-TOTP-and-U2F.t
@ -801,6 +803,7 @@ t/74-2F-Required-Issuer-Timeouts.t
t/74-2F-Required.t
t/75-2F-Registers.t
t/76-2F-Ext-with-BruteForce.t
t/76-2F-Ext-with-CodeActivation-Resend.t
t/76-2F-Ext-with-CodeActivation.t
t/76-2F-Ext-with-GrantSession.t
t/76-2F-Ext-with-History.t

View File

@ -497,7 +497,6 @@ sub _displayRegister {
);
}
# If only one 2F is available, redirect to it
my @am;
foreach my $m ( @{ $self->sfRModules } ) {
$self->logger->debug(
@ -505,9 +504,10 @@ sub _displayRegister {
if ( $m->{r}->( $req, $req->userData ) ) {
push @am,
{
CODE => $m->{m}->prefix,
URL => '/2fregisters/' . $m->{m}->prefix,
LOGO => $m->{m}->logo,
CODE => $m->{m}->prefix,
URL => '/2fregisters/' . $m->{m}->prefix,
LOGO => $m->{m}->logo,
LABEL => $m->{m}->label
};
}
}
@ -529,6 +529,7 @@ sub _displayRegister {
$self->userLogger->warn("Do not display 2F devices!");
}
# If only one 2F is available, redirect to it
return [ 302, [ Location => $self->conf->{portal} . $am[0]->{URL} ], [] ]
if (
@am == 1

View File

@ -0,0 +1,28 @@
# Base package for 2F Register modules
package Lemonldap::NG::Portal::2F::Register::Base;
use strict;
use Mouse;
our $VERSION = '2.0.15';
extends 'Lemonldap::NG::Portal::Main::Plugin';
has logo => ( is => 'rw', default => '2f.png' );
has label => ( is => 'rw' );
sub init {
my ($self) = @_;
# Set logo if overridden
$self->logo( $self->conf->{ $self->prefix . "2fLogo" } )
if ( $self->conf->{ $self->prefix . "2fLogo" } );
# Set label if provided, translation files will be used otherwise
$self->label( $self->conf->{ $self->prefix . "2fLabel" } )
if ( $self->conf->{ $self->prefix . "2fLabel" } );
return 1;
}
1;

View File

@ -5,10 +5,10 @@ use strict;
use Mouse;
use JSON qw(from_json to_json);
our $VERSION = '2.0.14';
our $VERSION = '2.0.15';
extends qw(
Lemonldap::NG::Portal::Main::Plugin
Lemonldap::NG::Portal::2F::Register::Base
Lemonldap::NG::Common::TOTP
);
@ -31,10 +31,6 @@ has ott => (
}
);
sub init {
return 1;
}
sub run {
my ( $self, $req, $action ) = @_;
my $user = $req->userData->{ $self->conf->{whatToTrace} };

View File

@ -6,10 +6,10 @@ use Mouse;
use JSON qw(from_json to_json);
use MIME::Base64 qw(encode_base64url decode_base64url);
our $VERSION = '2.0.12';
our $VERSION = '2.0.15';
extends qw(
Lemonldap::NG::Portal::Main::Plugin
Lemonldap::NG::Portal::2F::Register::Base
Lemonldap::NG::Portal::Lib::U2F
);
@ -22,8 +22,8 @@ has logo => ( is => 'rw', default => 'u2f.png' );
sub init {
my ($self) = @_;
return 0 unless $self->SUPER::init;
return 1;
return 0 unless ( $self->Lemonldap::NG::Portal::Lib::U2F::init() );
return ( $self->Lemonldap::NG::Portal::2F::Register::Base::init() );
}
# RUNNING METHODS

View File

@ -9,7 +9,7 @@ use Crypt::URandom;
our $VERSION = '2.0.12';
extends 'Lemonldap::NG::Portal::Main::Plugin';
extends 'Lemonldap::NG::Portal::2F::Register::Base';
with 'Lemonldap::NG::Portal::Lib::WebAuthn';
# INITIALIZATION
@ -52,8 +52,6 @@ has rpName => (
}
);
sub init { return 1; }
# RUNNING METHODS
# Return a Base64url encoded user handle

View File

@ -9,9 +9,9 @@ use Lemonldap::NG::Portal::Main::Constants qw(
PE_ERROR
);
our $VERSION = '2.0.10';
our $VERSION = '2.0.15';
extends 'Lemonldap::NG::Portal::Main::Plugin';
extends 'Lemonldap::NG::Portal::2F::Register::Base';
# INITIALIZATION
@ -20,11 +20,6 @@ has template => ( is => 'ro', default => 'yubikey2fregister' );
has welcome => ( is => 'ro', default => 'clickOnYubikey' );
has logo => ( is => 'rw', default => 'yubikey.png' );
sub init {
my ($self) = @_;
return 1;
}
# RUNNING METHODS
# Main method

View File

@ -77,10 +77,16 @@
<div class="card border-secondary">
<div class="card-body py-3">
<a href="<TMPL_VAR NAME="URL">" class="nodecor">
<img src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/<TMPL_VAR NAME="LOGO">" alt="<TMPL_VAR NAME="CODE">2F" title="<TMPL_VAR NAME="CODE">2F" />
<img src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/<TMPL_VAR NAME="LOGO">" alt="<TMPL_VAR NAME="CODE">2f" title="<TMPL_VAR NAME="LABEL">" />
</a>
</div>
<div class="card-footer text-white text-uppercase bg-secondary"><TMPL_VAR NAME="CODE">2F</div>
<div class="card-footer text-white text-uppercase bg-secondary">
<TMPL_IF LABEL>
<p><TMPL_VAR NAME="LABEL"></p>
<TMPL_ELSE>
<p trspan="<TMPL_VAR NAME="CODE">2f"></p>
</TMPL_IF>
</div>
</div>
</div>
</TMPL_LOOP>