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

(-)a/Koha/Patron/Password/Recovery.pm (-12 / +3 lines)
Lines 106-112 sub GetValidLinkInfo { Link Here
106
sub SendPasswordRecoveryEmail {
106
sub SendPasswordRecoveryEmail {
107
    my $borrower  = shift;    # Koha::Patron
107
    my $borrower  = shift;    # Koha::Patron
108
    my $userEmail = shift;    #to_address (the one specified in the request)
108
    my $userEmail = shift;    #to_address (the one specified in the request)
109
    my $update    = shift;
110
    my $staff     = shift // 0;
109
    my $staff     = shift // 0;
111
110
112
    my $schema = Koha::Database->new->schema;
111
    my $schema = Koha::Database->new->schema;
Lines 121-142 sub SendPasswordRecoveryEmail { Link Here
121
    my $days = $staff ? STAFF : PATRON;
120
    my $days = $staff ? STAFF : PATRON;
122
    my $expirydate =
121
    my $expirydate =
123
      dt_from_string()->add( days => $days );
122
      dt_from_string()->add( days => $days );
124
    if ($update) {
123
    my $rs = $schema->resultset('BorrowerPasswordRecovery')->update_or_create(
125
        my $rs =
126
          $schema->resultset('BorrowerPasswordRecovery')
127
          ->search( { borrowernumber => $borrower->borrowernumber, } );
128
        $rs->update(
129
            { uuid => $uuid_str, valid_until => $expirydate->datetime() } );
130
    }
131
    else {
132
        my $rs = $schema->resultset('BorrowerPasswordRecovery')->create(
133
            {
124
            {
134
                borrowernumber => $borrower->borrowernumber,
125
                borrowernumber => $borrower->borrowernumber,
135
                uuid           => $uuid_str,
126
                uuid           => $uuid_str,
136
                valid_until    => $expirydate->datetime()
127
                valid_until    => $expirydate->datetime()
137
            }
128
            },
129
            { key => 'primary' }
138
        );
130
        );
139
    }
140
131
141
    # create link
132
    # create link
142
    my $opacbase = C4::Context->preference('OPACBaseURL') || '';
133
    my $opacbase = C4::Context->preference('OPACBaseURL') || '';
(-)a/members/notices.pl (-4 / +1 lines)
Lines 100-110 if ( $op eq 'send_password_reset' ) { Link Here
100
100
101
    if ($emailaddr) {
101
    if ($emailaddr) {
102
102
103
        # check if there's already a recovery in process
104
        my $update = ValidateBorrowernumber( $patron->borrowernumber );
105
106
        # send staff initiated password recovery
103
        # send staff initiated password recovery
107
        SendPasswordRecoveryEmail( $patron, $emailaddr, $update, 1 );
104
        SendPasswordRecoveryEmail( $patron, $emailaddr, 1 );
108
    }
105
    }
109
106
110
    # redirect to self to avoid form submission on refresh
107
    # redirect to self to avoid form submission on refresh
(-)a/opac/opac-password-recovery.pl (-1 / +1 lines)
Lines 133-139 if ( $query->param('sendEmail') || $query->param('resendEmail') ) { Link Here
133
            username                => $username
133
            username                => $username
134
        );
134
        );
135
    }
135
    }
136
    elsif ( SendPasswordRecoveryEmail( $borrower, $email, scalar $query->param('resendEmail') ) ) {    # generate uuid and send recovery email
136
    elsif ( SendPasswordRecoveryEmail( $borrower, $email ) ) {    # generate uuid and send recovery email
137
        $template->param(
137
        $template->param(
138
            mail_sent => 1,
138
            mail_sent => 1,
139
            email     => $email
139
            email     => $email
(-)a/t/db_dependent/Passwordrecovery.t (-3 / +2 lines)
Lines 200-206 ok( Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery($borrowernum Link Here
200
my $borrower = Koha::Patrons->search( { userid => $userid1 } )->next;
200
my $borrower = Koha::Patrons->search( { userid => $userid1 } )->next;
201
my $success;
201
my $success;
202
warning_is {
202
warning_is {
203
    $success = Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 0); }
203
    $success = Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1 ); }
204
    "Fake sendmail",
204
    "Fake sendmail",
205
    '[SendPasswordRecoveryEmail] expecting fake sendmail';
205
    '[SendPasswordRecoveryEmail] expecting fake sendmail';
206
ok( $success == 1, '[SendPasswordRecoveryEmail] Returns 1 on success');
206
ok( $success == 1, '[SendPasswordRecoveryEmail] Returns 1 on success');
Lines 212-218 my $bpr = $schema->resultset('BorrowerPasswordRecovery')->search( { borrowernumb Link Here
212
my $tempuuid1 = $bpr->next->uuid;
212
my $tempuuid1 = $bpr->next->uuid;
213
213
214
warning_is {
214
warning_is {
215
    Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1, 1); }
215
    Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail($borrower, $email1 ); }
216
    "Fake sendmail",
216
    "Fake sendmail",
217
    '[SendPasswordRecoveryEmail] expecting fake sendmail';
217
    '[SendPasswordRecoveryEmail] expecting fake sendmail';
218
218
219
- 

Return to bug 31739