From 5be64ffebe1472dc8ffe5466d047d8db9a80874e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 2 Mar 2023 13:41:16 +0100 Subject: [PATCH] Bug 33104: Encrypt password Signed-off-by: Jonathan Field Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Bookseller.pm | 7 ++- Koha/Acquisition/Bookseller/Interface.pm | 33 ++++++++++++++ .../prog/en/modules/acqui/supplier.tt | 43 +++++++++++++------ 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index a11c765643..0ce6b9dd95 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -122,7 +122,12 @@ sub interfaces { sub { $self->interfaces->delete; for my $interface (@$interfaces) { - $self->_result->add_to_aqbookseller_interfaces($interface); + Koha::Acquisition::Bookseller::Interface->new( + { + %$interface, + vendor_id => $self->id, + } + )->store; } } ); diff --git a/Koha/Acquisition/Bookseller/Interface.pm b/Koha/Acquisition/Bookseller/Interface.pm index b038f539e4..a7a232f454 100644 --- a/Koha/Acquisition/Bookseller/Interface.pm +++ b/Koha/Acquisition/Bookseller/Interface.pm @@ -16,6 +16,7 @@ package Koha::Acquisition::Bookseller::Interface; # along with Koha; if not, see . use Modern::Perl; +use Koha::Encryption; use base qw( Koha::Object ); @@ -29,6 +30,38 @@ Koha::Acquisition::Bookseller::Interface - Koha Bookseller interface Object clas =cut +=head3 store + + $self->store; + +Specific store method to encrypt the password. + +=cut + +sub store { + my ($self) = @_; + + if ( $self->password ) { + $self->password(Koha::Encryption->new->encrypt_hex($self->password)); + } + + return $self->SUPER::store; +} + +=head3 plain_text_password + + my $plain_text_password = $self->plain_text_password; + +Decrypt the password and return its plain text form. + +=cut + +sub plain_text_password { + my ($self) = @_; + return Koha::Encryption->new->decrypt_hex($self->password) + if $self->password; +} + =head3 _type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index 2543a8c1e1..ec8e951bce 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -357,18 +357,28 @@

Interfaces

- [% FOR interface IN vendor.interfaces %] + [% FOR i IN vendor.interfaces %]
- [% interface.name | html %] + [% i.name | html %]
    -
  • -
  • Type: [% interface.type | html %]
  • -
  • URI: [% interface.uri | html %]
  • -
  • Login: [% interface.login | html %]
  • -
  • Password: [% interface.password | html %]
  • -
  • Account email: [% interface.account_email | html %]
  • -
  • Notes : [% interface.notes | html %]
  • - + [% IF i.type %] +
  • Type: [% i.type | html %]
  • + [% END %] + [% IF i.uri %] +
  • URI: [% i.uri | html %]
  • + [% END %] + [% IF i.login %] +
  • Login: [% i.login | html %]
  • + [% END %] + [% IF i.password %] +
  • Password: Show
  • + [% END %] + [% IF i.account_email %] +
  • Account email: [% i.account_email | html %]
  • + [% END %] + [% IF i.notes %] +
  • Notes : [% i.notes | html %]
  • + [% END %]
[% END %] @@ -528,9 +538,14 @@ } [% IF vendor %] - let interfaces = [% To.json(vendor.interfaces.unblessed) | $raw %]; + let interfaces = []; + [% FOR i_object IN vendor.interfaces %] + [% SET i = i_object.unblessed %] + [% SET i.password = i_object.plain_text_password %] + interfaces.push([% To.json(i) | $raw %]); + [% END %] [% ELSE %] - let interfaces = []; + let interfaces = []; [% END %] function serialize_interface_form(){ interfaces = []; @@ -635,6 +650,10 @@ $(this).next('.contact_claimissues_hidden').val($(this).is(':checked') ? '1' : '0'); }); + $('body').on('click', '.show_password', null, function(e){ + e.preventDefault(); + $(this).parent().replaceWith($(this).data('plain-text-password')); + }); refresh_aliases(); refresh_interfaces(); -- 2.39.5