From 714899c7f8535f6f970726c784a0074722c86665 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Sat, 12 Dec 2015 02:10:06 +0000 Subject: [PATCH] Bug 15343 - Allow user to set password on opac-memberentry.pl This patch allows patrons to create thier own password during OPAC self registration. It sets the password field to be hidden by default, and allows for a system generated password if no password is supplied and field is not mandatory 1 - Apply patch 2 - run updatedatabase.pl 3 - Check syspref "PatronSelfRegistrationBorrowerUnwantedField" - it should contain 'password' 4 - Check self registration on opac - there should be no change 5 - Remove 'password' from PatronSelfRegistrationBorrowerUnwantedField 6 - Password field should now be visible in OPAC self registration 7 - Register a patron: If no passwor is supplied you should get a system generated password 8 - Register a patron with a password, your password should be used 9 - Add 'password' to PatronSelfRegistrationBorrowerMnadatoryField 10 - Attempt to register a patron with no password - it should fail 11 - Try all combinations if mismatched/short/missing passwords and view correct error messages 12 - prove t/db_dependent/Members.t Sponsored by : Do Space (www.dospace.org) Signed-off-by: Jesse Weaver Signed-off-by: Mirko Tietgen Signed-off-by: Jonathan Druart Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/Members.pm | 13 ++++---- ...trationBorrowrUnwantedField_by_default.sql | 1 + .../bootstrap/en/modules/opac-memberentry.tt | 31 +++++++++++++++++++ opac/opac-memberentry.pl | 10 +++++- t/db_dependent/Members.t | 11 ++++++- 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_15343-add_password_to_PatronSelfRegistrationBorrowrUnwantedField_by_default.sql diff --git a/C4/Members.pm b/C4/Members.pm index 8a47566fdd..cab4560af4 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -2411,17 +2411,18 @@ sub AddMember_Opac { my ( %borrower ) = @_; $borrower{'categorycode'} = C4::Context->preference('PatronSelfRegistrationDefaultCategory'); - - my $sr = new String::Random; - $sr->{'A'} = [ 'A'..'Z', 'a'..'z' ]; - my $password = $sr->randpattern("AAAAAAAAAA"); - $borrower{'password'} = $password; + if (not defined $borrower{'password'}){ + my $sr = new String::Random; + $sr->{'A'} = [ 'A'..'Z', 'a'..'z' ]; + my $password = $sr->randpattern("AAAAAAAAAA"); + $borrower{'password'} = $password; + } $borrower{'cardnumber'} = fixup_cardnumber(); my $borrowernumber = AddMember(%borrower); - return ( $borrowernumber, $password ); + return ( $borrowernumber, $borrower{'password'} ); } =head2 AddEnrolmentFeeIfNeeded diff --git a/installer/data/mysql/atomicupdate/bug_15343-add_password_to_PatronSelfRegistrationBorrowrUnwantedField_by_default.sql b/installer/data/mysql/atomicupdate/bug_15343-add_password_to_PatronSelfRegistrationBorrowrUnwantedField_by_default.sql new file mode 100644 index 0000000000..0f3ad0f912 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_15343-add_password_to_PatronSelfRegistrationBorrowrUnwantedField_by_default.sql @@ -0,0 +1 @@ +UPDATE systempreferences SET value = CONCAT_WS('|', IF(value='', NULL, value), "password") WHERE variable="PatronSelfRegistrationBorrowerUnwantedField" AND value NOT LIKE "%password%"; 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 3f3428d8f0..90f4b83b26 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -60,6 +60,8 @@ [% IF field == "email" %]
  • Contact information: primary email address
  • [% END %] [% IF field == "emailpro" %]
  • Contact information: secondary email address
  • [% END %] [% IF field == "B_email" %]
  • Alternate address information: email address
  • [% END %] + [% IF field == "password_match" %]
  • Passwords do not match! password
  • [% END %] + [% IF field == "password_invalid" %]
  • Password does not meet minium requirements! password
  • [% END %] [% END %] Please correct the errors and resubmit. @@ -777,8 +779,37 @@ [% END %] [% UNLESS action == 'edit' %] +
    + Contact information + [% UNLESS hidden.defined('password') %] +
    Your password must be at least [% minpassw %] characters long. + [% IF mandatory.defined('password') %] +
    You must enter a password!
    +
      +
    1. + +
    2. +
    3. + +
    4. +
    + [% ELSE %] +
    If you do not enter a password a system generated password will be created +
      +
    1. + +
    2. +
    3. + +
    4. +
    + [% END %] + [% END %] +
    +
      +
    1. diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 32da43026c..86135cd206 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -67,6 +67,7 @@ $template->param( action => $action, hidden => $hidden, mandatory => $mandatory, + minpassw => C4::Context->preference('minPasswordLength'), member_titles => GetTitles() || undef, branches => GetBranchesLoop(), OPACPatronDetails => C4::Context->preference('OPACPatronDetails'), @@ -114,7 +115,6 @@ if ( $action eq 'create' ) { my $verification_token = md5_hex( \%borrower ); $borrower{'password'} = random_string(".........."); - Koha::Borrower::Modifications->new( verification_token => $verification_token ) ->AddModifications(\%borrower); @@ -308,6 +308,7 @@ sub CheckMandatoryFields { } sub CheckForInvalidFields { + my $minpw = C4::Context->preference('minPasswordLength'); my $borrower = shift; my @invalidFields; if ($borrower->{'email'}) { @@ -319,6 +320,13 @@ sub CheckForInvalidFields { if ($borrower->{'B_email'}) { push(@invalidFields, "B_email") if (!Email::Valid->address($borrower->{'B_email'})); } + if ( $borrower->{'password'} ne $borrower->{'password2'} ){ + push(@invalidFields, "password_match"); + } + if ( $borrower->{'password'} && $minpw && (length($borrower->{'password'}) < $minpw) ) { + push(@invalidFields, "password_invalid"); + } + return \@invalidFields; } diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index 4c87e84cb9..13e6b57f28 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 74; +use Test::More tests => 76; use Test::MockModule; use Data::Dumper; use C4::Context; @@ -365,6 +365,15 @@ sub _find_member { return $found; } +# Regression tests for BZ15343 +my $password=""; +( $borrowernumber, $password ) = AddMember_Opac(surname=>"Dick",firstname=>'Philip',branchcode => $library2->{branchcode}); +is( $password =~ /^[a-zA-Z]{10}$/ , 1, 'Test for autogenerated password if none submitted'); +( $borrowernumber, $password ) = AddMember_Opac(surname=>"Deckard",firstname=>"Rick",password=>"Nexus-6",branchcode => $library2->{branchcode}); +is( $password eq "Nexus-6", 1, 'Test password used if submitted'); + + + ### ------------------------------------- ### ### Testing GetAge() / SetAge() functions ### ### ------------------------------------- ### -- 2.39.5