Lines 25-33
use Koha::Exceptions::Patron;
Link Here
|
25 |
|
25 |
|
26 |
use base qw( Auth::GoogleAuth ); |
26 |
use base qw( Auth::GoogleAuth ); |
27 |
|
27 |
|
28 |
use constant CONFIRM_NOTICE_REG => '2FA_ENABLE'; |
|
|
29 |
use constant CONFIRM_NOTICE_DEREG => '2FA_DISABLE'; |
30 |
|
31 |
=head1 NAME |
28 |
=head1 NAME |
32 |
|
29 |
|
33 |
Koha::Auth::TwoFactorAuth- Koha class deal with Two factor authentication |
30 |
Koha::Auth::TwoFactorAuth- Koha class deal with Two factor authentication |
Lines 40-46
my $secret = Koha::AuthUtils::generate_salt( 'weak', 16 );
Link Here
|
40 |
my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => $secret }); |
37 |
my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => $secret }); |
41 |
my $image_src = $auth->qr_code; |
38 |
my $image_src = $auth->qr_code; |
42 |
my $ok = $auth->verify( $pin_code, 1 ); |
39 |
my $ok = $auth->verify( $pin_code, 1 ); |
43 |
$auth->send_confirm_notice({ patron => $patron }); |
|
|
44 |
|
40 |
|
45 |
It's based on Auth::GoogleAuth |
41 |
It's based on Auth::GoogleAuth |
46 |
|
42 |
|
Lines 108-149
sub qr_code {
Link Here
|
108 |
return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines |
104 |
return "data:image/png;base64,". encode_base64( $data, q{} ); # does not contain newlines |
109 |
} |
105 |
} |
110 |
|
106 |
|
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 |
|
149 |
1; |
107 |
1; |