@@ -, +, @@ --- Koha/Exceptions/Patron/Modification.pm | 12 ++++++++++++ Koha/Patron/Modification.pm | 19 +++++++++++++++++++ opac/opac-memberentry.pl | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 Koha/Exceptions/Patron/Modification.pm --- a/Koha/Exceptions/Patron/Modification.pm +++ a/Koha/Exceptions/Patron/Modification.pm @@ -0,0 +1,12 @@ +package Koha::Exceptions::Patron::Modification; + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken' => { + isa => 'Koha::Exceptions::Object', + description => "The verification token given already exists", + }, +); + +1; --- a/Koha/Patron/Modification.pm +++ a/Koha/Patron/Modification.pm @@ -23,6 +23,9 @@ use Carp; use Koha::Database; +use Koha::Patron::Modifications; +use Koha::Exceptions::Patron::Modification; + use base qw(Koha::Object); =head1 NAME @@ -33,6 +36,22 @@ Koha::Patron::Modification - Class represents a request to modify or create a pa =cut +=head2 store + +=cut + +sub store { + my ($self) = @_; + + if ( $self->verification_token ) { + if ( Koha::Patron::Modifications->search( { verification_token => $self->verification_token } )->count() ) { + Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken->throw; + } + } + + return $self->SUPER::store(); +} + =head2 approve $m->approve(); --- a/opac/opac-memberentry.pl +++ a/opac/opac-memberentry.pl @@ -139,6 +139,9 @@ if ( $action eq 'create' ) { $template->param( 'email' => $borrower{'email'} ); my $verification_token = md5_hex( time().{}.rand().{}.$$ ); + while ( Koha::Patron::Modifications->search( { verification_token => $verification_token } )->count() ) { + $verification_token = md5_hex( time().{}.rand().{}.$$ ); + } $borrower{password} = random_string(".........."); $borrower{verification_token} = $verification_token; --