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

(-)a/C4/Passwordrecovery.pm (-8 / +7 lines)
Lines 102-110 sub GetValidLinkInfo { Link Here
102
=cut
102
=cut
103
103
104
sub SendPasswordRecoveryEmail {
104
sub SendPasswordRecoveryEmail {
105
    my $borrower = shift; # from GetMember
105
    my $borrower = shift; # Koha::Borrower
106
    my $userEmail = shift; #to_address (the one specified in the request)
106
    my $userEmail = shift; #to_address (the one specified in the request)
107
    my $protocol = shift; #only required to determine if 'http' or 'https'
108
    my $update = shift;
107
    my $update = shift;
109
108
110
    my $schema = Koha::Database->new->schema;
109
    my $schema = Koha::Database->new->schema;
Lines 119-144 sub SendPasswordRecoveryEmail { Link Here
119
    if($update){
118
    if($update){
120
        my $rs = $schema->resultset('BorrowerPasswordRecovery')->search(
119
        my $rs = $schema->resultset('BorrowerPasswordRecovery')->search(
121
        {
120
        {
122
            borrowernumber => $borrower->{'borrowernumber'},
121
            borrowernumber => $borrower->borrowernumber,
123
        });
122
        });
124
        $rs->update({uuid => $uuid_str, valid_until => $expirydate->datetime()});
123
        $rs->update({uuid => $uuid_str, valid_until => $expirydate->datetime()});
125
    } else {
124
    } else {
126
         my $rs = $schema->resultset('BorrowerPasswordRecovery')->create({
125
         my $rs = $schema->resultset('BorrowerPasswordRecovery')->create({
127
            borrowernumber=>$borrower->{'borrowernumber'},
126
            borrowernumber=>$borrower->borrowernumber,
128
            uuid => $uuid_str,
127
            uuid => $uuid_str,
129
            valid_until=> $expirydate->datetime()
128
            valid_until=> $expirydate->datetime()
130
         });
129
         });
131
    }
130
    }
132
131
133
    # create link
132
    # create link
134
    my $uuidLink = $protocol . C4::Context->preference( 'OPACBaseURL' ) . "/cgi-bin/koha/opac-password-recovery.pl?uniqueKey=$uuid_str";
133
    my $uuidLink = C4::Context->preference( 'OPACBaseURL' ) . "/cgi-bin/koha/opac-password-recovery.pl?uniqueKey=$uuid_str";
135
134
136
    # prepare the email
135
    # prepare the email
137
    my $letter = C4::Letters::GetPreparedLetter (
136
    my $letter = C4::Letters::GetPreparedLetter (
138
        module => 'members',
137
        module => 'members',
139
        letter_code => 'PASSWORD_RESET',
138
        letter_code => 'PASSWORD_RESET',
140
        branchcode => $borrower->{branchcode},
139
        branchcode => $borrower->branchcode,
141
        substitute => {passwordreseturl => $uuidLink, user => $borrower->{userid} },
140
        substitute => {passwordreseturl => $uuidLink, user => $borrower->userid },
142
    );
141
    );
143
142
144
    # define to/from emails
143
    # define to/from emails
Lines 146-152 sub SendPasswordRecoveryEmail { Link Here
146
145
147
    C4::Letters::EnqueueLetter( {
146
    C4::Letters::EnqueueLetter( {
148
         letter => $letter,
147
         letter => $letter,
149
         borrowernumber => $borrower->{borrowernumber},
148
         borrowernumber => $borrower->borrowernumber,
150
         to_address => $userEmail,
149
         to_address => $userEmail,
151
         from_address => $kohaEmail,
150
         from_address => $kohaEmail,
152
         message_transport_type => 'email',
151
         message_transport_type => 'email',
(-)a/opac/opac-password-recovery.pl (-9 / +8 lines)
Lines 6-16 use CGI; Link Here
6
6
7
use C4::Auth;
7
use C4::Auth;
8
use C4::Koha;
8
use C4::Koha;
9
use C4::Members qw(changepassword Search);
9
use C4::Members qw(changepassword);
10
use C4::Output;
10
use C4::Output;
11
use C4::Context;
11
use C4::Context;
12
use C4::Passwordrecovery qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery);
12
use C4::Passwordrecovery qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery);
13
use Koha::AuthUtils qw(hash_password);
13
use Koha::AuthUtils qw(hash_password);
14
use Koha::Borrowers;
14
my $query = new CGI;
15
my $query = new CGI;
15
use HTML::Entities;
16
use HTML::Entities;
16
17
Lines 49-55 my $errPassNotMatch; Link Here
49
my $errPassTooShort;
50
my $errPassTooShort;
50
51
51
if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
52
if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
52
    my $protocol = $query->https() ? "https://" : "http://";
53
    #try with the main email
53
    #try with the main email
54
    $email ||= ''; # avoid undef
54
    $email ||= ''; # avoid undef
55
    my $borrower;
55
    my $borrower;
Lines 57-66 if ( $query->param('sendEmail') || $query->param('resendEmail') ) { Link Here
57
57
58
    # Find the borrower by his userid or email
58
    # Find the borrower by his userid or email
59
    if( $username ){
59
    if( $username ){
60
        $search_results = Search({ userid => $username });
60
        $search_results = [ Koha::Borrowers->search({ userid => $username }) ];
61
    }
61
    }
62
    elsif ( $email ){
62
    elsif ( $email ){
63
        $search_results = Search({ '' => $email }, undef, undef, undef, ['emailpro', 'email', 'B_email']);
63
        $search_results = [ Koha::Borrowers->search({-or => {email => $email, emailpro=> $email, B_email=>$email }}) ];
64
    }
64
    }
65
65
66
    if(scalar @$search_results > 1){ # Many matching borrowers
66
    if(scalar @$search_results > 1){ # Many matching borrowers
Lines 68-75 if ( $query->param('sendEmail') || $query->param('resendEmail') ) { Link Here
68
       $errTooManyEmailFound = 1;
68
       $errTooManyEmailFound = 1;
69
    }
69
    }
70
    elsif( $borrower = shift @$search_results ){ # One matching borrower
70
    elsif( $borrower = shift @$search_results ){ # One matching borrower
71
        $username ||= $borrower->{'userid'};
71
        $username ||= $borrower->userid;
72
        my @emails = ( $borrower->{'email'}, $borrower->{'emailpro'}, $borrower->{'B_email'} );
72
        my @emails = ( $borrower->email, $borrower->emailpro, $borrower->B_email );
73
        # Is the given email one of the borrower's ?
73
        # Is the given email one of the borrower's ?
74
        if( $email && !($email ~~ @emails) ){
74
        if( $email && !($email ~~ @emails) ){
75
             $hasError    = 1;
75
             $hasError    = 1;
Lines 84-90 if ( $query->param('sendEmail') || $query->param('resendEmail') ) { Link Here
84
             $errNoBorrowerEmail = 1;
84
             $errNoBorrowerEmail = 1;
85
        }
85
        }
86
        # Check if a password reset already issued for this borrower AND we are not asking for a new email
86
        # Check if a password reset already issued for this borrower AND we are not asking for a new email
87
        elsif( ValidateBorrowernumber( $borrower->{'borrowernumber'} ) && !$query->param('resendEmail') ){
87
        elsif( ValidateBorrowernumber( $borrower->borrowernumber ) && !$query->param('resendEmail') ){
88
            $hasError                = 1;
88
            $hasError                = 1;
89
            $errAlreadyStartRecovery = 1;
89
            $errAlreadyStartRecovery = 1;
90
        }
90
        }
Lines 106-112 if ( $query->param('sendEmail') || $query->param('resendEmail') ) { Link Here
106
            username                => $username
106
            username                => $username
107
        );
107
        );
108
    }
108
    }
109
    elsif ( SendPasswordRecoveryEmail( $borrower, $email, $protocol, $query->param('resendEmail') ) ) {#generate uuid and send recovery email
109
    elsif ( SendPasswordRecoveryEmail( $borrower, $email, $query->param('resendEmail') ) ) {#generate uuid and send recovery email
110
        $template->param(
110
        $template->param(
111
            mail_sent => 1,
111
            mail_sent => 1,
112
            email     => $email
112
            email     => $email
113
- 

Return to bug 8753