--- /dev/null
+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;
use Koha::Database;
+use Koha::Patron::Modifications;
+use Koha::Exceptions::Patron::Modification;
+
use base qw(Koha::Object);
=head1 NAME
=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();
$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;
#!/usr/bin/perl
use Modern::Perl;
-use Test::More tests => 8;
+use Test::More tests => 9;
+use Try::Tiny;
-use C4::Context;
use t::lib::TestBuilder;
+
+use C4::Context;
use C4::Members;
BEGIN {
}
)->store();
+## Ensure duplicate verification tokens cannot be added to the database
+try {
+ Koha::Patron::Modification->new(
+ {
+ verification_token => '1234567890',
+ surname => 'Hall',
+ firstname => 'Daria'
+ }
+ )->store();
+} catch {
+ ok( $_->isa('Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken'),
+ 'Attempting to add a duplicate verification token to the database should raise a Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken exception' );
+};
+
## Get the new pending modification
my $borrower =
Koha::Patron::Modifications->find( { verification_token => '1234567890' } );