View | Details | Raw Unified | Return to bug 17494
Collapse All | Expand All

(-)a/Koha/Exceptions/Patron/Modification.pm (+12 lines)
Line 0 Link Here
1
package Koha::Exceptions::Patron::Modification;
2
3
use Modern::Perl;
4
5
use Exception::Class (
6
    'Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken' => {
7
        isa => 'Koha::Exceptions::Object',
8
        description => "The verification token given already exists",
9
    },
10
);
11
12
1;
(-)a/Koha/Patron/Modification.pm (+19 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::Patron::Modifications;
27
use Koha::Exceptions::Patron::Modification;
28
26
use base qw(Koha::Object);
29
use base qw(Koha::Object);
27
30
28
=head1 NAME
31
=head1 NAME
Lines 33-38 Koha::Patron::Modification - Class represents a request to modify or create a pa Link Here
33
36
34
=cut
37
=cut
35
38
39
=head2 store
40
41
=cut
42
43
sub store {
44
    my ($self) = @_;
45
46
    if ( $self->verification_token ) {
47
        if ( Koha::Patron::Modifications->search( { verification_token => $self->verification_token } )->count() ) {
48
            Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken->throw;
49
        }
50
    }
51
52
    return $self->SUPER::store();
53
}
54
36
=head2 approve
55
=head2 approve
37
56
38
$m->approve();
57
$m->approve();
(-)a/opac/opac-memberentry.pl (+3 lines)
Lines 139-144 if ( $action eq 'create' ) { Link Here
139
            $template->param( 'email' => $borrower{'email'} );
139
            $template->param( 'email' => $borrower{'email'} );
140
140
141
            my $verification_token = md5_hex( time().{}.rand().{}.$$ );
141
            my $verification_token = md5_hex( time().{}.rand().{}.$$ );
142
            while ( Koha::Patron::Modifications->search( { verification_token => $verification_token } )->count() ) {
143
                $verification_token = md5_hex( time().{}.rand().{}.$$ );
144
            }
142
145
143
            $borrower{password}           = random_string("..........");
146
            $borrower{password}           = random_string("..........");
144
            $borrower{verification_token} = $verification_token;
147
            $borrower{verification_token} = $verification_token;
(-)a/t/db_dependent/Koha_borrower_modifications.t (-3 / +18 lines)
Lines 1-10 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 8;
4
use Test::More tests => 9;
5
use Try::Tiny;
5
6
6
use C4::Context;
7
use t::lib::TestBuilder;
7
use t::lib::TestBuilder;
8
9
use C4::Context;
8
use C4::Members;
10
use C4::Members;
9
11
10
BEGIN {
12
BEGIN {
Lines 27-32 Koha::Patron::Modification->new( Link Here
27
    }
29
    }
28
)->store();
30
)->store();
29
31
32
## Ensure duplicate verification tokens cannot be added to the database
33
try {
34
    Koha::Patron::Modification->new(
35
        {
36
            verification_token => '1234567890',
37
            surname            => 'Hall',
38
            firstname          => 'Daria'
39
        }
40
    )->store();
41
} catch {
42
    ok( $_->isa('Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken'),
43
        'Attempting to add a duplicate verification token to the database should raise a Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken exception' );
44
};
45
30
## Get the new pending modification
46
## Get the new pending modification
31
my $borrower =
47
my $borrower =
32
  Koha::Patron::Modifications->find( { verification_token => '1234567890' } );
48
  Koha::Patron::Modifications->find( { verification_token => '1234567890' } );
33
- 

Return to bug 17494