From f5373b7a5ea125f5b3123ab038a727d13315390f Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Thu, 3 Dec 2020 13:10:18 -0300 Subject: [PATCH] Bug 27148: Fix bug on self registration when user category is hidden This patch fixes the bug when there is no patron category available for selection in self registration form. It uses PatronSelfRegistrationDefaultCategory to get patron's password length and strength. To test: 1. Do not apply this patch 2. Allow SeflRegistration, set PatronSelfRegistrationDefaultCategory to a valid patron category and finally add categorycode to PatronSelfRegistrationBorrowerUnwantedField 3. Go to opac and enter self registration form CHECK => There is no patron category available for selection => Password's info alert shows "Password must contain at least undefined characters" 4. Fill the form setting a password and send. CHECH => You get an exception saying "You must provide a patron's category to validate password's strength and length" 5. Apply this patch and restart_all 6. repeat steps 3 and 4 SUCCESS => Password's info alert message shows a number instead of "undefined" => Password's strength and length checks are working => If you change default category's lenght or strength parameter it get's reflected when you refresh the page => When you click send, patron is saved Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- .../opac-tmpl/bootstrap/en/modules/opac-memberentry.tt | 8 +++++--- opac/opac-memberentry.pl | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index 6736294268..d7b3be3987 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -1234,10 +1234,12 @@ [% UNLESS patron %] var PWD_STRONG_MSG = _("Password must contain at least %s characters, including UPPERCASE, lowercase and numbers"); var PWD_WEAK_MSG = _("Password must contain at least %s characters"); + var default_password_length = [% defaultCategory.effective_min_password_length | html %]; + var default_strong_password = [% defaultCategory.effective_require_strong_password | html %]; $(document).ready(function() { var setPwdMessage = function() { - var require_strong = $('select#borrower_categorycode option:selected').data('pwdStrong'); - var min_lenght = $('select#borrower_categorycode option:selected').data('pwdLength'); + var require_strong = $('select#borrower_categorycode option:selected').data('pwdStrong')||default_strong_password; + var min_lenght = $('select#borrower_categorycode option:selected').data('pwdLength')||default_password_length; $('#password_alert').html((require_strong?PWD_STRONG_MSG:PWD_WEAK_MSG).format(min_lenght)); }; setPwdMessage(); @@ -1246,6 +1248,6 @@ [% END %] //]]> - [% PROCESS 'password_check.inc' new_password => 'borrower_password', category_selector => '#borrower_categorycode', RequireStrongPassword => patron.category.effective_require_strong_password, minPasswordLength => patron.category.effective_min_password_length %] + [% PROCESS 'password_check.inc' new_password => 'borrower_password', category_selector => '#borrower_categorycode', RequireStrongPassword => patron ? patron.category.effective_require_strong_password : defaultCategory.effective_require_strong_password, minPasswordLength => patron ? patron.category.effective_min_password_length : defaultCategory.effective_min_password_length %] [% END %] diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 6b7afc0175..a3f1ae61b8 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -93,12 +93,15 @@ if ( defined $min ) { ); } +my $defaultCategory = Koha::Patron::Categories->find(C4::Context->preference('PatronSelfRegistrationDefaultCategory')); + $template->param( action => $action, hidden => GetHiddenFields( $mandatory, $action ), mandatory => $mandatory, libraries => \@libraries, OPACPatronDetails => C4::Context->preference('OPACPatronDetails'), + defaultCategory => $defaultCategory, ); my $attributes = ParsePatronAttributes($borrowernumber,$cgi); @@ -476,7 +479,7 @@ sub CheckForInvalidFields { push( @invalidFields, "password_match" ); } if ( $borrower->{'password'} ) { - my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $borrower->{password}, Koha::Patron::Categories->find($borrower->{categorycode}) ); + my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $borrower->{password}, Koha::Patron::Categories->find($borrower->{categorycode}||C4::Context->preference('PatronSelfRegistrationDefaultCategory')) ); unless ( $is_valid ) { push @invalidFields, 'password_too_short' if $error eq 'too_short'; push @invalidFields, 'password_too_weak' if $error eq 'too_weak'; -- 2.39.5