Lines 19-28
use Modern::Perl;
Link Here
|
19 |
use GD::Barcode; |
19 |
use GD::Barcode; |
20 |
use MIME::Base64 qw( encode_base64 ); |
20 |
use MIME::Base64 qw( encode_base64 ); |
21 |
|
21 |
|
|
|
22 |
use C4::Letters; |
22 |
use Koha::Exceptions; |
23 |
use Koha::Exceptions; |
|
|
24 |
use Koha::Exceptions::Patron; |
23 |
|
25 |
|
24 |
use base qw( Auth::GoogleAuth ); |
26 |
use base qw( Auth::GoogleAuth ); |
25 |
|
27 |
|
|
|
28 |
use constant CONFIRM_NOTICE_REG => '2FA_REGISTER'; |
29 |
use constant CONFIRM_NOTICE_DEREG => '2FA_DEREGISTER'; |
30 |
|
26 |
=head1 NAME |
31 |
=head1 NAME |
27 |
|
32 |
|
28 |
Koha::Auth::TwoFactorAuth- Koha class deal with Two factor authentication |
33 |
Koha::Auth::TwoFactorAuth- Koha class deal with Two factor authentication |
Lines 33-39
use Koha::Auth::TwoFactorAuth;
Link Here
|
33 |
|
38 |
|
34 |
my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 ); |
39 |
my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 ); |
35 |
my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => $secret }); |
40 |
my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => $secret }); |
|
|
41 |
my $image_src = $auth->qr_code; |
36 |
my $ok = $auth->verify( $pin_code, 1 ); |
42 |
my $ok = $auth->verify( $pin_code, 1 ); |
|
|
43 |
$auth->send_confirm_notice({ patron => $patron }); |
37 |
|
44 |
|
38 |
It's based on Auth::GoogleAuth |
45 |
It's based on Auth::GoogleAuth |
39 |
|
46 |
|
Lines 101-104
sub qr_code {
Link Here
|
101 |
return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines |
108 |
return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines |
102 |
} |
109 |
} |
103 |
|
110 |
|
|
|
111 |
=head3 send_confirm_notice |
112 |
|
113 |
$auth->send_confirm_notice({ patron => $p, deregister => 1 }); |
114 |
|
115 |
Send a notice to confirm (de)registering 2FA. |
116 |
Parameter patron is mandatory. |
117 |
If there is no deregister param, a register notice is sent. |
118 |
If the patron has no email address, we throw an exception. |
119 |
|
120 |
=cut |
121 |
|
122 |
sub send_confirm_notice { |
123 |
my ( $self, $params ) = @_; |
124 |
my $patron = $params->{patron}; |
125 |
my $deregister = $params->{deregister}; |
126 |
|
127 |
Koha::Exceptions::MissingParameter->throw("Mandatory patron parameter missing") |
128 |
unless $patron && ref($patron) eq 'Koha::Patron'; |
129 |
Koha::Exceptions::Patron::MissingEmailAddress->throw |
130 |
if !$patron->notice_email_address; |
131 |
|
132 |
my $letter = C4::Letters::GetPreparedLetter ( |
133 |
module => 'members', # called patrons on interface |
134 |
letter_code => $deregister ? CONFIRM_NOTICE_DEREG : CONFIRM_NOTICE_REG, |
135 |
branchcode => $patron->branchcode, |
136 |
lang => $patron->lang, |
137 |
tables => { |
138 |
'branches' => $patron->branchcode, |
139 |
'borrowers' => $patron->id, |
140 |
}, |
141 |
); |
142 |
C4::Letters::EnqueueLetter({ |
143 |
letter => $letter, |
144 |
borrowernumber => $patron->id, |
145 |
message_transport_type => 'email', |
146 |
}) or warn "Couldnt enqueue 2FA notice for patron ". $patron->id; |
147 |
} |
148 |
|
104 |
1; |
149 |
1; |