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

(-)a/Koha/Patron/Modification.pm (+50 lines)
Lines 155-160 sub approve { Link Here
155
    return $self->delete();
155
    return $self->delete();
156
}
156
}
157
157
158
=head3 notify_library_of_registration
159
160
    my $message_id = $patron_to_be_verified->notify_library_of_registration( $email_patron_registrations );
161
162
Send patron registration verification email to library if EmailPatronRegistrations system preference is enabled.
163
164
Returns message ID.
165
166
=cut
167
168
sub notify_library_of_registration {
169
    my ( $self, $email_patron_registrations ) = @_;
170
171
    if (
172
        my $letter = C4::Letters::GetPreparedLetter(
173
            module      => 'members',
174
            letter_code => 'OPAC_REG_VERIFY_LIB',
175
            branchcode  => $self->branchcode,
176
            lang        => $self->lang || 'default',
177
            tables      => { 'borrower_modifications' => $self->verification_token },
178
        )
179
        )
180
    {
181
        my $to_address;
182
        if ( $email_patron_registrations eq "BranchEmailAddress" ) {
183
            my $library = Koha::Libraries->find( $self->branchcode );
184
            $to_address = $library->inbound_email_address;
185
        } elsif ( $email_patron_registrations eq "KohaAdminEmailAddress" ) {
186
            $to_address = C4::Context->preference('ReplytoDefault')
187
                || C4::Context->preference('KohaAdminEmailAddress');
188
        } else {
189
            $to_address =
190
                   C4::Context->preference('EmailAddressForPatronRegistrations')
191
                || C4::Context->preference('ReplytoDefault')
192
                || C4::Context->preference('KohaAdminEmailAddress');
193
        }
194
195
        my $message_id = C4::Letters::EnqueueLetter(
196
            {
197
                letter                 => $letter,
198
                to_address             => $to_address,
199
                message_transport_type => 'email'
200
            }
201
        ) or warn "can't enqueue letter $letter";
202
        if ($message_id) {
203
            return $message_id;
204
        }
205
    }
206
}
207
158
=head3 type
208
=head3 type
159
209
160
=cut
210
=cut
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-confirmation.tt (-11 / +17 lines)
Lines 52-57 Link Here
52
                        <form action="/cgi-bin/koha/opac-registration-verify.pl" method="post" name="confirm_registration" id="confirm_registration">
52
                        <form action="/cgi-bin/koha/opac-registration-verify.pl" method="post" name="confirm_registration" id="confirm_registration">
53
                            [% INCLUDE 'csrf-token.inc' %]
53
                            [% INCLUDE 'csrf-token.inc' %]
54
                            <input type="hidden" name="token" value="[% token | html %]" />
54
                            <input type="hidden" name="token" value="[% token | html %]" />
55
                            <input type="hidden" name="library_approval" value="[% library_approval | html %]" />
55
                            <input type="hidden" name="op" value="cud-confirmed" />
56
                            <input type="hidden" name="op" value="cud-confirmed" />
56
                            <input type="submit" value="Confirm" class="btn btn-primary" />
57
                            <input type="submit" value="Confirm" class="btn btn-primary" />
57
                        </form>
58
                        </form>
Lines 60-67 Link Here
60
                    <div id="registration-complete">
61
                    <div id="registration-complete">
61
                        <h1>Registration complete!</h1>
62
                        <h1>Registration complete!</h1>
62
63
63
                        <p>You have successfully registered your new account.</p>
64
                        <p>You have successfully registered a new account.</p>
64
                        [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') %]
65
66
                        [% IF library_approval %]
67
                            <p>An password recovery email has been sent.</p>
68
                        [% ELSIF Koha.Preference('PatronSelfRegistrationPrefillForm') %]
65
                            <p>To log in, use the following credentials:</p>
69
                            <p>To log in, use the following credentials:</p>
66
70
67
                            <p id="patron-userid-p" class="registration-line">
71
                            <p id="patron-userid-p" class="registration-line">
Lines 80-92 Link Here
80
                                </p>
84
                                </p>
81
                            [% END %]
85
                            [% END %]
82
86
83
                            <p id="patron-instructions">
87
                            [% UNLESS Koha.Preference('PatronSelfRegistrationVerifyByEmail') == "library" %]
84
                                [% IF borrower.category.effective_change_password %]
88
                                <p id="patron-instructions">
85
                                    <span>For your convenience, the login box on this page has been pre-filled with this data. Please log in and change your password.</span>
89
                                    [% IF borrower.category.effective_change_password %]
86
                                [% ELSE %]
90
                                        <span>For your convenience, the login box on this page has been pre-filled with this data. Please log in and change your password.</span>
87
                                    <span>For your convenience, the login box on this page has been pre-filled with this data. Please log in.</span>
91
                                    [% ELSE %]
88
                                [% END %]
92
                                        <span>For your convenience, the login box on this page has been pre-filled with this data. Please log in.</span>
89
                            </p>
93
                                    [% END %]
94
                                </p>
95
                            [% END %]
90
                        [% END %]
96
                        [% END %]
91
97
92
                        [% IF ( PatronSelfRegistrationAdditionalInstructions ) %]
98
                        [% IF ( PatronSelfRegistrationAdditionalInstructions ) %]
Lines 109-121 Link Here
109
                                <fieldset class="brief">
115
                                <fieldset class="brief">
110
                                    <legend>Log in to your account:</legend>
116
                                    <legend>Log in to your account:</legend>
111
                                    [% PROCESS login_label for="userid" %]
117
                                    [% PROCESS login_label for="userid" %]
112
                                    [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') %]
118
                                    [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') && Koha.Preference('PatronSelfRegistrationVerifyByEmail') != "library" %]
113
                                        <input class="form-control" type="text" id="userid" size="10" name="login_userid" value="[% borrower.userid | html %]" autocomplete="off" />
119
                                        <input class="form-control" type="text" id="userid" size="10" name="login_userid" value="[% borrower.userid | html %]" autocomplete="off" />
114
                                    [% ELSE %]
120
                                    [% ELSE %]
115
                                        <input class="form-control" type="text" id="userid" size="10" name="login_userid" value="" autocomplete="off" />
121
                                        <input class="form-control" type="text" id="userid" size="10" name="login_userid" value="" autocomplete="off" />
116
                                    [% END %]
122
                                    [% END %]
117
                                    <label for="password">Password:</label>
123
                                    <label for="password">Password:</label>
118
                                    [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') %]
124
                                    [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') && Koha.Preference('PatronSelfRegistrationVerifyByEmail') != "library" %]
119
                                        <input class="form-control" type="password" id="password" size="10" name="login_password" value="[% password_cleartext | html %]" autocomplete="off" />
125
                                        <input class="form-control" type="password" id="password" size="10" name="login_password" value="[% password_cleartext | html %]" autocomplete="off" />
120
                                    [% ELSE %]
126
                                    [% ELSE %]
121
                                        <input class="form-control" type="password" id="password" size="10" name="login_password" value="" autocomplete="off" />
127
                                        <input class="form-control" type="password" id="password" size="10" name="login_password" value="" autocomplete="off" />
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-email-sent.tt (-3 / +7 lines)
Lines 31-41 Link Here
31
31
32
            <div class="[% column_class | html %]">
32
            <div class="[% column_class | html %]">
33
                <div id="registration-confirmation-pending" class="maincontent">
33
                <div id="registration-confirmation-pending" class="maincontent">
34
                    <h1>Please confirm your registration</h1>
34
                    <h1>Your account is pending confirmation</h1>
35
                    <div id="confirmation-pending" class="alert alert-info">
35
                    <div id="confirmation-pending" class="alert alert-info">
36
                        <p>A confirmation email will be sent shortly to the email address <strong>[% email | html %]</strong>.</p>
36
                        [% IF Koha.Preference('PatronSelfRegistrationVerifyByEmail') == "patron" %]
37
                            <p>A confirmation email will be sent shortly to the email address <strong>[% email | html %]</strong>.</p>
37
38
38
                        <p>Your account will not be activated until you follow the link provided in the confirmation email.</p>
39
                            <p>Your account will not be activated until you follow the link provided in the confirmation email.</p>
40
                        [% ELSE %]
41
                            <p>An email will be sent shortly to the library to confirm the activation of your account.</p>
42
                        [% END %]
39
                    </div>
43
                    </div>
40
                    <!-- /#confirmation-pending -->
44
                    <!-- /#confirmation-pending -->
41
                </div>
45
                </div>
(-)a/opac/opac-memberentry.pl (-18 / +28 lines)
Lines 175-181 if ( $op eq 'cud-create' ) { Link Here
175
    } elsif ( !$libraries->find( $borrower{branchcode} ) ) {
175
    } elsif ( !$libraries->find( $borrower{branchcode} ) ) {
176
        die "Branchcode not allowed";    # They hack the form
176
        die "Branchcode not allowed";    # They hack the form
177
    } else {
177
    } else {
178
        if ( C4::Context->preference('PatronSelfRegistrationVerifyByEmail') ) {
178
        if ( C4::Context->preference('PatronSelfRegistrationVerifyByEmail') ne "off" ) {
179
            ( $template, $borrowernumber, $cookie ) = get_template_and_user(
179
            ( $template, $borrowernumber, $cookie ) = get_template_and_user(
180
                {
180
                {
181
                    template_name   => "opac-registration-email-sent.tt",
181
                    template_name   => "opac-registration-email-sent.tt",
Lines 198-224 if ( $op eq 'cud-create' ) { Link Here
198
198
199
            $borrower{extended_attributes} = to_json($attributes);
199
            $borrower{extended_attributes} = to_json($attributes);
200
            $borrower{borrowernumber}      = 0;                      # prevent warn Missing value for PK column
200
            $borrower{borrowernumber}      = 0;                      # prevent warn Missing value for PK column
201
            Koha::Patron::Modification->new( \%borrower )->store();
201
            my $mod_borrower = Koha::Patron::Modification->new( \%borrower )->store();
202
202
203
            #Send verification email
203
            #Send verification email
204
            my $letter = C4::Letters::GetPreparedLetter(
204
            if ( C4::Context->preference('PatronSelfRegistrationVerifyByEmail') eq "library" ) {
205
                module      => 'members',
206
                letter_code => 'OPAC_REG_VERIFY',
207
                lang        => 'default',           # Patron does not have a preferred language defined yet
208
                tables      => {
209
                    borrower_modifications => $verification_token,
210
                },
211
            );
212
205
213
            my $message_id = C4::Letters::EnqueueLetter(
206
                # Send new patron registration verification to library
214
                {
207
                my $notify_library = C4::Context->preference('EmailPatronRegistrations');
215
                    letter                 => $letter,
208
                if ($notify_library) {
216
                    message_transport_type => 'email',
209
                    my $message_id = $mod_borrower->notify_library_of_registration($notify_library);
217
                    to_address             => $borrower{'email'},
210
                    C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id;
218
                    from_address           => C4::Context->preference('KohaAdminEmailAddress'),
219
                }
211
                }
220
            );
212
            } else {
221
            C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id;
213
                my $letter = C4::Letters::GetPreparedLetter(
214
                    module      => 'members',
215
                    letter_code => 'OPAC_REG_VERIFY',
216
                    lang        => 'default',           # Patron does not have a preferred language defined yet
217
                    tables      => {
218
                        borrower_modifications => $verification_token,
219
                    },
220
                );
221
222
                my $message_id = C4::Letters::EnqueueLetter(
223
                    {
224
                        letter                 => $letter,
225
                        message_transport_type => 'email',
226
                        to_address             => $borrower{'email'},
227
                        from_address           => C4::Context->preference('KohaAdminEmailAddress'),
228
                    }
229
                );
230
                C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id;
231
            }
222
        } else {
232
        } else {
223
            $borrower{password} ||=
233
            $borrower{password} ||=
224
                Koha::AuthUtils::generate_password( Koha::Patron::Categories->find( $borrower{categorycode} ) );
234
                Koha::AuthUtils::generate_password( Koha::Patron::Categories->find( $borrower{categorycode} ) );
(-)a/opac/opac-registration-verify.pl (-3 / +13 lines)
Lines 32-37 use Koha::Patrons; Link Here
32
use Koha::Patron::Consent;
32
use Koha::Patron::Consent;
33
use Koha::Patron::Modifications;
33
use Koha::Patron::Modifications;
34
use Koha::Patron::Categories;
34
use Koha::Patron::Categories;
35
use Koha::Patron::Password::Recovery qw( SendPasswordRecoveryEmail );
35
36
36
my $cgi = CGI->new;
37
my $cgi = CGI->new;
37
my $dbh = C4::Context->dbh;
38
my $dbh = C4::Context->dbh;
Lines 41-48 unless ( C4::Context->preference('PatronSelfRegistration') ) { Link Here
41
    exit;
42
    exit;
42
}
43
}
43
44
44
my $token = $cgi->param('token');
45
my $token            = $cgi->param('token');
45
my $op    = $cgi->param('op');
46
my $library_approval = $cgi->param("library_approval");
47
my $op               = $cgi->param('op');
46
my $confirmed;
48
my $confirmed;
47
if ( $op && $op eq 'cud-confirmed' ) {
49
if ( $op && $op eq 'cud-confirmed' ) {
48
    $confirmed = 1;
50
    $confirmed = 1;
Lines 73-79 if ( $rego_found Link Here
73
            authnotrequired => C4::Context->preference("OpacPublic") ? 1 : 0,
75
            authnotrequired => C4::Context->preference("OpacPublic") ? 1 : 0,
74
        }
76
        }
75
    );
77
    );
76
    $template->param( "token" => $token );
78
    $template->param(
79
        "token"          => $token,
80
        library_approval => $library_approval,
81
    );
77
} elsif ( $rego_found
82
} elsif ( $rego_found
78
    and $confirmed )
83
    and $confirmed )
79
{
84
{
Lines 121-126 if ( $rego_found Link Here
121
        $template->param( password_cleartext => $patron->plain_text_password );
126
        $template->param( password_cleartext => $patron->plain_text_password );
122
        $template->param( borrower           => $patron );
127
        $template->param( borrower           => $patron );
123
128
129
        if ($library_approval) {
130
            SendPasswordRecoveryEmail( $patron, $patron->notice_email_address );
131
            $template->param( library_approval => 1 );
132
        }
133
124
        # If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
134
        # If 'AutoEmailNewUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
125
        if ( C4::Context->preference("AutoEmailNewUser") ) {
135
        if ( C4::Context->preference("AutoEmailNewUser") ) {
126
136
(-)a/t/db_dependent/Koha/Patron/Modifications.t (-2 / +30 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use utf8;
20
use utf8;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 508-510 subtest 'dateofbirth tests' => sub { Link Here
508
508
509
    $schema->storage->txn_rollback;
509
    $schema->storage->txn_rollback;
510
};
510
};
511
- 
511
512
subtest 'notify_library_of_registration() tests' => sub {
513
514
    plan tests => 1;
515
516
    $schema->storage->txn_begin;
517
518
    Koha::Patron::Modifications->search->delete;
519
520
    t::lib::Mocks::mock_preference( 'EmailAddressForPatronRegistrations',  'library@localhost' );
521
    t::lib::Mocks::mock_preference( 'EmailPatronRegistrations',            'EmailAddressForPatronRegistrations' );
522
    t::lib::Mocks::mock_preference( 'PatronSelfRegistrationVerifyByEmail', 'library' );
523
524
    # Create new pending modification
525
    my $borrower = Koha::Patron::Modification->new(
526
        {
527
            verification_token => '1234567890',
528
            changed_fields     => 'surname,firstname',
529
            surname            => 'Hall',
530
            firstname          => 'Kyle'
531
        }
532
    )->store();
533
534
    my $message_id = $borrower->notify_library_of_registration( C4::Context->preference('EmailPatronRegistrations') );
535
536
    ok( $message_id, "Verification email is generated" );
537
538
    $schema->storage->txn_rollback;
539
};

Return to bug 25090