From 095717b003e9b1e149107b9d8a81e1dbf2c50c02 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Wed, 13 Mar 2019 09:10:56 +0100 Subject: [PATCH] Bug 29480: Add new systempreference PatronSelfRegistrationUseridGenerationMethod and add email as option. Test plan - Install patch and run koha-upgrade-schema - The systempreference PatronSelfRegistrationUseridGenerationMethod should be found in the adminstrative interface under OPAC -> Self registration and modification - Also make sure - Make sure that PatronSelfRegistration is set to Allow and PatronSelfRegistrationDefaultCategory is set to an existing borrower category - Make sure that PatronSelfModificationBorrowerUnwantedField doesn't prevent the input of an email address in the self registration form. (I.e., make sure "email" is NOT selected for exclusion.) - Go to opac and self register a patron and verify that the userid is on the form firstname.surname. - Change systempreference to 'email' - Go to OPAC and self register a patron and make sure to add a valid email address. - Verify the that the userid is the email adress. - Go to OPAC and self register a patron using the SAME valid email adress as above (to provoke a conflicting userid). - Verify that the userid is on the form firstname.surname. --- Koha/Patron.pm | 41 ++++++++++++------- ...trationUseridGenerationMethod_syspref.perl | 11 +++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/opac.pref | 7 ++++ 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 68877c2e10..26bb3616a6 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1518,21 +1518,32 @@ Set a generated userid ($firstname.$surname if there is a $firstname, or $surnam sub generate_userid { my ($self) = @_; my $offset = 0; - my $firstname = $self->firstname // q{}; - my $surname = $self->surname // q{}; - #The script will "do" the following code and increment the $offset until the generated userid is unique - do { - $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; - $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; - my $userid = lc(($firstname)? "$firstname.$surname" : $surname); - $userid = NFKD( $userid ); - $userid =~ s/\p{NonspacingMark}//g; - $userid .= $offset unless $offset == 0; - $self->userid( $userid ); - $offset++; - } while (! $self->has_valid_userid ); - - return $self; + my $email = $self->first_valid_email_address; + + if (defined($email) && $email ne '' && length($email) <= 75 && + C4::Context->preference('PatronSelfRegistrationUseridGenerationMethod') eq 'email') { + # Uniqueness of email as userid is verified by + # has_valid_userid, with fallback to the default method. + $self->userid( $email ); + } + + if (!$self->has_valid_userid) { + my $firstname = $self->firstname // q{}; + my $surname = $self->surname // q{}; + #The script will "do" the following code and increment the $offset until the generated userid is unique + do { + $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; + $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; + my $userid = lc(($firstname)? "$firstname.$surname" : $surname); + $userid = NFKD( $userid ); + $userid =~ s/\p{NonspacingMark}//g; + $userid .= $offset unless $offset == 0; + $self->userid( $userid ); + $offset++; + } while (! $self->has_valid_userid ); + } + + return $self; } =head3 add_extended_attribute diff --git a/installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl b/installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl new file mode 100644 index 0000000000..5895bee1e2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + $dbh->do(<<'EOF'); +INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES +('PatronSelfRegistrationUseridGenerationMethod', 'default', 'default|email', 'Method for generating userid of of a borrower when self registering in OPAC. Fallback to generating a userid from the name of the borrower.', ''); +EOF + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 29480, "Add new system preference PatronSelfRegistrationUseridGenerationMethod"); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 8d86f2d47a..73ea8931fe 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -514,6 +514,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('PatronSelfRegistrationExpireTemporaryAccountsDelay','0',NULL,'If PatronSelfRegistrationDefaultCategory is enabled, this system preference controls how long a patron can have a temporary status before the account is deleted automatically. It is an integer value representing a number of days to wait before deleting a temporary patron account. Setting it to 0 disables the deleting of temporary accounts.','Integer'), ('PatronSelfRegistrationLibraryList','',NULL,'Only display libraries listed. If empty, all libraries are displayed.','Free'), ('PatronSelfRegistrationPrefillForm','1',NULL,'Display password and prefill login form after a patron has self registered','YesNo'), +('PatronSelfRegistrationUseridGenerationMethod', 'default', 'default|email', 'Method for generating userid of of a borrower when self registering in OPAC. Fallback to generating a userid from the name of the borrower.', ''), ('PatronSelfRegistrationVerifyByEmail','0',NULL,'If enabled, any patron attempting to register themselves via the OPAC will be required to verify themselves via email to activate their account.','YesNo'), ('PatronsPerPage','20','20','Number of Patrons Per Page displayed by default','Integer'), ('EnablePayPalOpacPayments', '0', NULL , 'Enables the ability to pay fees and fines from the OPAC via PayPal', 'YesNo' ), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 9f9ec8dd08..14b1a4e012 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -863,6 +863,13 @@ OPAC: yes: Require no: "Don't require" - patrons to confirm their email address by entering it twice. + - + - Use + - pref: PatronSelfRegistrationUseridGenerationMethod + choices: + default: "firstname.surname[uniqueness number, if needed]" + email: "email address" + - to generate the user name of a borrower when self registering in OPAC. - - pref: OPACPatronDetails choices: -- 2.20.1