Bug 16275: Do not allow a self registration with an existing email address
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 23 Apr 2016 16:01:24 +0000 (17:01 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 9 Sep 2016 11:57:54 +0000 (11:57 +0000)
To avoid multiple registrations, it would be good to check the unicity
of the primary email address.
This patchset adds a new pref PatronSelfRegistrationEmailMustBeUnique.
If on, a patron will get "This email address already exists in our
database" if he try to register with an existing email address.

Test plan:
1/ Register a new patron with an email address
2/ Make an other registration using the same email address
=> With the pref PatronSelfRegistrationEmailMustBeUnique on, you won't be allowed
=> With the pref off, no change should be noticed.

Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Work as described, no errors.

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
opac/opac-memberentry.pl

index 77e17e3..66db306 100644 (file)
@@ -65,6 +65,9 @@
                                 [% IF field == "password_match" %]<li>Passwords do not match! <a href="#password">password</a></li>[% END %]
                                 [% IF field == "password_invalid" %]<li>Password does not meet minimum requirements! <a href="#password">password</a></li>[% END %]
                                 [% IF field == "password_spaces" %]<li>Password contains leading and/or trailing spaces! <a href="#password">password</a></li>[% END %]
+                                [% IF field == "duplicate_email" %]
+                                    <li>This email address already exists in our database.</li>
+                                [% END %]
                             [% END %]
                         </ul>
                         Please correct the errors and resubmit.
index 8b5ade9..6dcc832 100755 (executable)
@@ -352,7 +352,14 @@ sub CheckForInvalidFields {
     my $borrower = shift;
     my @invalidFields;
     if ($borrower->{'email'}) {
-        push(@invalidFields, "email") if (!Email::Valid->address($borrower->{'email'}));
+        unless ( Email::Valid->address($borrower->{'email'}) ) {
+            push(@invalidFields, "email");
+        } elsif ( C4::Context->preference("PatronSelfRegistrationEmailMustBeUnique") ) {
+            my $patrons_with_same_email = Koha::Patrons->search( { email => $borrower->{email} })->count;
+            if ( $patrons_with_same_email ) {
+                push @invalidFields, "duplicate_email";
+            }
+        }
     }
     if ($borrower->{'emailpro'}) {
         push(@invalidFields, "emailpro") if (!Email::Valid->address($borrower->{'emailpro'}));