From 8c7ae857a286a2b73573f6f216eedfb90ea46753 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 5 Nov 2019 12:58:45 +0000 Subject: [PATCH] Bug 23473: (follow-up) Catch and show password exceptions Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Patrons/Import.pm | 22 +++++++++++++++- .../prog/en/modules/tools/import_borrowers.tt | 25 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index ed1e68deaf..06a411ede2 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -22,6 +22,7 @@ use namespace::clean; use Carp; use Text::CSV; use Encode qw( decode_utf8 ); +use Try::Tiny; use C4::Members; @@ -303,7 +304,26 @@ sub import_patrons { } } if ($overwrite_passwords){ - $patron->set_password({ password => $borrower{password} }); + try { + $patron->set_password({ password => $borrower{password} }); + } + catch { + if ( $_->isa('Koha::Exceptions::Password::TooShort') ) { + push @errors, { passwd_too_short => 1, borrowernumber => $borrowernumber, length => $_->{length}, min_length => $_->{min_length} }; + } + elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) { + push @errors, { passwd_whitespace => 1, borrowernumber => $borrowernumber } ; + } + elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) { + push @errors, { passwd_too_weak => 1, borrowernumber => $borrowernumber } ; + } + elsif ( $_->isa('Koha::Exceptions::Password::Plugin') ) { + push @errors, { passwd_plugin_err => 1, borrowernumber => $borrowernumber } ; + } + else { + push @errors, { passwd_unknown_err => 1, borrowernumber => $borrowernumber } ; + } + } } if ($extended) { if ($ext_preserve) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt index e7c463124b..70fe71712b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt @@ -115,6 +115,31 @@ Userid [% e.userid | html %] is already used by another patron. [% END %] + [% IF e.passwd_too_short %] +
  • + Password is too short for patron with borrowernumber [% e.borrowernumber | html %]. Minimum length is [% e.min_length %], length is [% e.length %] +
  • + [% END %] + [% IF e.passwd_whitespace %] +
  • + Password contains whitespace for patron with borrowernumber [% e.borrowernumber | html %]. +
  • + [% END %] + [% IF e.passwd_too_weak %] +
  • + Password is too weak for patron with borrowernumber [% e.borrowernumber | html %]. +
  • + [% END %] + [% IF e.passwd_plugin_err %] +
  • + Password plugin error for patron with borrowernumber [% e.borrowernumber | html %]. +
  • + [% END %] + [% IF e.passwd_unknown_err %] +
  • + Password error for patron with borrowernumber [% e.borrowernumber | html %]. +
  • + [% END %] [% END %] -- 2.39.5