View | Details | Raw Unified | Return to bug 33904
Collapse All | Expand All

(-)a/Koha/Auth/TwoFactorAuth.pm (-20 / +22 lines)
Lines 53-62 It's based on Auth::GoogleAuth Link Here
53
=cut
53
=cut
54
54
55
sub new {
55
sub new {
56
    my ($class, $params) = @_;
56
    my ( $class, $params ) = @_;
57
    my $patron   = $params->{patron};
57
    my $patron   = $params->{patron};
58
    my $secret32 = $params->{secret32};
58
    my $secret32 = $params->{secret32};
59
    my $secret = $params->{secret};
59
    my $secret   = $params->{secret};
60
60
61
    # FIXME Raise an exception if the syspref is disabled
61
    # FIXME Raise an exception if the syspref is disabled
62
62
Lines 64-89 sub new { Link Here
64
        unless $patron && ref($patron) eq 'Koha::Patron';
64
        unless $patron && ref($patron) eq 'Koha::Patron';
65
65
66
    my $type = 'secret32';
66
    my $type = 'secret32';
67
    if( $secret32 ) {
67
    if ($secret32) {
68
        Koha::Exceptions::BadParameter->throw("Secret32 should be base32")
68
        Koha::Exceptions::BadParameter->throw("Secret32 should be base32")
69
            if $secret32 =~ /[^a-z2-7]/;
69
            if $secret32 =~ /[^a-z2-7]/;
70
    } elsif( $secret ) {
70
    } elsif ($secret) {
71
        $type = 'secret';
71
        $type = 'secret';
72
    } elsif( $patron->secret ) {
72
    } elsif ( $patron->secret ) {
73
        $secret32 = $patron->decoded_secret; # saved already in base32
73
        $secret32 = $patron->decoded_secret;    # saved already in base32
74
    } else {
74
    } else {
75
        Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret");
75
        Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret");
76
    }
76
    }
77
77
78
    my $issuer = Encode::encode_utf8($patron->library->branchname);
78
    my $issuer = Encode::encode_utf8( $patron->library->branchname );
79
    my $key_id = sprintf "%s_%s",
79
    my $key_id = sprintf "%s_%s",
80
      $issuer, ( $patron->email || $patron->userid );
80
        $issuer, ( $patron->email || $patron->userid );
81
81
82
    return $class->SUPER::new({
82
    return $class->SUPER::new(
83
        $type => $secret32 || $secret,
83
        {
84
        issuer => $issuer,
84
            $type  => $secret32 || $secret,
85
        key_id => $key_id,
85
            issuer => $issuer,
86
    });
86
            key_id => $key_id,
87
        }
88
    );
87
}
89
}
88
90
89
=head3 qr_code
91
=head3 qr_code
Lines 97-109 sub new { Link Here
97
=cut
99
=cut
98
100
99
sub qr_code {
101
sub qr_code {
100
    my ( $self ) = @_;
102
    my ($self) = @_;
103
104
    my $otpauth = $self->SUPER::qr_code( undef, undef, undef, 1 );
101
105
102
    my $otpauth = $self->SUPER::qr_code( undef, undef, undef, 1);
106
    # no need to pass secret, key and issuer again
103
        # no need to pass secret, key and issuer again
104
    my $qrcode = GD::Barcode->new( 'QRcode', $otpauth, { Ecc => 'M', Version => 10, ModuleSize => 4 } );
107
    my $qrcode = GD::Barcode->new( 'QRcode', $otpauth, { Ecc => 'M', Version => 10, ModuleSize => 4 } );
105
    my $data = $qrcode->plot->png;
108
    my $data   = $qrcode->plot->png;
106
    return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines
109
    return "data:image/png;base64," . encode_base64( $data, q{} );    # does not contain newlines
107
}
110
}
108
111
109
1;
112
1;
110
- 

Return to bug 33904