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

(-)a/C4/Members.pm (-26 lines)
Lines 76-86 BEGIN { Link Here
76
        &changepassword
76
        &changepassword
77
    );
77
    );
78
78
79
    #Insert data
80
    push @EXPORT, qw(
81
        &AddMember_Opac
82
    );
83
84
    #Check data
79
    #Check data
85
    push @EXPORT, qw(
80
    push @EXPORT, qw(
86
        &checkuserpassword
81
        &checkuserpassword
Lines 738-764 sub IssueSlip { Link Here
738
    );
733
    );
739
}
734
}
740
735
741
=head2 AddMember_Opac
742
743
=cut
744
745
sub AddMember_Opac {
746
    my ( %borrower ) = @_;
747
748
    $borrower{'categorycode'} //= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
749
    my $password = $borrower{password};
750
    if (not defined $password){
751
        my $sr = new String::Random;
752
        $sr->{'A'} = [ 'A'..'Z', 'a'..'z' ];
753
        $password = $sr->randpattern("AAAAAAAAAA");
754
        $borrower{'password'} = $password;
755
    }
756
757
    my $patron = Koha::Patron->new(\%borrower)->store;
758
759
    return ( $patron->borrowernumber, $password );
760
}
761
762
=head2 DeleteExpiredOpacRegistrations
736
=head2 DeleteExpiredOpacRegistrations
763
737
764
    Delete accounts that haven't been upgraded from the 'temporary' category
738
    Delete accounts that haven't been upgraded from the 'temporary' category
(-)a/Koha/Patron.pm (-3 / +14 lines)
Lines 127-132 sub trim_whitespaces { Link Here
127
    return $self;
127
    return $self;
128
}
128
}
129
129
130
sub plain_text_password {
131
    my ( $self, $password ) = @_;
132
    if ( $password ) {
133
        $self->{_plain_text_password} = $password;
134
        return $self;
135
    }
136
    return $self->{_plain_text_password}
137
        if $self->{_plain_text_password};
138
139
    return;
140
}
141
130
sub store {
142
sub store {
131
    my ($self) = @_;
143
    my ($self) = @_;
132
144
Lines 182-188 sub store { Link Here
182
                }
194
                }
183
195
184
                # Make a copy of the plain text password for later use
196
                # Make a copy of the plain text password for later use
185
                my $plain_text_password = $self->password;
197
                $self->plain_text_password( $self->password );
186
198
187
                # Create a disabled account if no password provided
199
                # Create a disabled account if no password provided
188
                $self->password( $self->password
200
                $self->password( $self->password
Lines 214-221 sub store { Link Here
214
                            'sync'           => 1,
226
                            'sync'           => 1,
215
                            'syncstatus'     => 'new',
227
                            'syncstatus'     => 'new',
216
                            'hashed_pin' =>
228
                            'hashed_pin' =>
217
                              Koha::NorwegianPatronDB::NLEncryptPIN(
229
                              Koha::NorwegianPatronDB::NLEncryptPIN($self->plain_text_password),
218
                                $plain_text_password),
219
                        }
230
                        }
220
                      );
231
                      );
221
                }
232
                }
(-)a/opac/opac-memberentry.pl (-2 / +4 lines)
Lines 169-175 if ( $action eq 'create' ) { Link Here
169
                $verification_token = md5_hex( time().{}.rand().{}.$$ );
169
                $verification_token = md5_hex( time().{}.rand().{}.$$ );
170
            }
170
            }
171
171
172
            $borrower{password}           = Koha::AuthUtils::generate_password unless $borrower{password};
172
            $borrower{password}          = Koha::AuthUtils::generate_password unless $borrower{password};
173
            $borrower{verification_token} = $verification_token;
173
            $borrower{verification_token} = $verification_token;
174
174
175
            Koha::Patron::Modification->new( \%borrower )->store();
175
            Koha::Patron::Modification->new( \%borrower )->store();
Lines 207-212 if ( $action eq 'create' ) { Link Here
207
            $template->param( OpacPasswordChange =>
207
            $template->param( OpacPasswordChange =>
208
                  C4::Context->preference('OpacPasswordChange') );
208
                  C4::Context->preference('OpacPasswordChange') );
209
209
210
            $borrower{categorycode}     ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
211
            $borrower{password}         ||= Koha::AuthUtils::generate_password;
210
            my $patron = Koha::Patron->new( \%borrower )->store;
212
            my $patron = Koha::Patron->new( \%borrower )->store;
211
            if ( $patron ) {
213
            if ( $patron ) {
212
                C4::Members::Attributes::SetBorrowerAttributes( $patron->borrowernumber, $attributes );
214
                C4::Members::Attributes::SetBorrowerAttributes( $patron->borrowernumber, $attributes );
Lines 220-226 if ( $action eq 'create' ) { Link Here
220
                    );
222
                    );
221
                }
223
                }
222
224
223
                $template->param( password_cleartext => $password );
225
                $template->param( password_cleartext => $patron->plain_text_password );
224
                $template->param( borrower => $patron->unblessed );
226
                $template->param( borrower => $patron->unblessed );
225
            } else {
227
            } else {
226
                # FIXME Handle possible errors here
228
                # FIXME Handle possible errors here
(-)a/opac/opac-registration-verify.pl (-7 / +8 lines)
Lines 23-28 use C4::Auth; Link Here
23
use C4::Output;
23
use C4::Output;
24
use C4::Members;
24
use C4::Members;
25
use C4::Form::MessagingPreferences;
25
use C4::Form::MessagingPreferences;
26
use Koha::AuthUtils;
26
use Koha::Patrons;
27
use Koha::Patrons;
27
use Koha::Patron::Modifications;
28
use Koha::Patron::Modifications;
28
29
Lines 59-75 if ( Link Here
59
    $template->param(
60
    $template->param(
60
        OpacPasswordChange => C4::Context->preference('OpacPasswordChange') );
61
        OpacPasswordChange => C4::Context->preference('OpacPasswordChange') );
61
62
62
    my $borrower = $m->unblessed();
63
    my $patron_attrs = $m->unblessed;
64
    $patron_attrs->{password} ||= Koha::AuthUtils::generate_password;
63
65
64
    my $password;
66
    $patron_attrs->{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
65
    ( $borrowernumber, $password ) = AddMember_Opac(%$borrower);
67
    my $patron = Koha::Patron->new( $patron_attrs )->store;
66
68
67
    if ($borrowernumber) {
69
    if ($patron) {
68
        $m->delete();
70
        $m->delete();
69
        C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences');
71
        C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $patron->borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences');
70
72
71
        $template->param( password_cleartext => $password );
73
        $template->param( password_cleartext => $patron->plain_text_password );
72
        my $patron = Koha::Patrons->find( $borrowernumber );
73
        $template->param( borrower => $patron->unblessed );
74
        $template->param( borrower => $patron->unblessed );
74
        $template->param(
75
        $template->param(
75
            PatronSelfRegistrationAdditionalInstructions =>
76
            PatronSelfRegistrationAdditionalInstructions =>
(-)a/t/db_dependent/Members.t (-12 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 50;
20
use Test::More tests => 47;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 376-391 sub _find_member { Link Here
376
    return $found;
376
    return $found;
377
}
377
}
378
378
379
# Regression tests for BZ15343
380
my $password="";
381
( $borrowernumber, $password ) = AddMember_Opac(surname=>"Dick",firstname=>'Philip',branchcode => $library2->{branchcode});
382
is( $password =~ /^[a-zA-Z]{10}$/ , 1, 'Test for autogenerated password if none submitted');
383
( $borrowernumber, $password ) = AddMember_Opac(surname=>"Deckard",firstname=>"Rick",password=>"Nexus-6",branchcode => $library2->{branchcode});
384
is( $password eq "Nexus-6", 1, 'Test password used if submitted');
385
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
386
my $hashed_up =  Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password});
387
is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' );
388
389
$schema->storage->txn_rollback;
379
$schema->storage->txn_rollback;
390
380
391
subtest 'Koha::Patron->store (invalid categorycode) tests' => sub {
381
subtest 'Koha::Patron->store (invalid categorycode) tests' => sub {
392
- 

Return to bug 20287