Bug 8753 - Use Koha::Borrowers instead of C4::Members
Use the new library to search for borrowers. Changed how the $borrower variable is used since it is now a Koha::Borrower object. Removed the $protocol parameter from the generated link. It should be included in the OPACBaseURL syspref. modified: C4/Passwordrecovery.pm modified: opac/opac-password-recovery.pl Signed-off-by: Marc Veron <veron@veron.ch> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
This commit is contained in:
parent
b99f1dcbfc
commit
0f2aea716a
|
|
@ -102,9 +102,8 @@ sub GetValidLinkInfo {
|
|||
=cut
|
||||
|
||||
sub SendPasswordRecoveryEmail {
|
||||
my $borrower = shift; # from GetMember
|
||||
my $borrower = shift; # Koha::Borrower
|
||||
my $userEmail = shift; #to_address (the one specified in the request)
|
||||
my $protocol = shift; #only required to determine if 'http' or 'https'
|
||||
my $update = shift;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
|
|
@ -119,26 +118,26 @@ sub SendPasswordRecoveryEmail {
|
|||
if($update){
|
||||
my $rs = $schema->resultset('BorrowerPasswordRecovery')->search(
|
||||
{
|
||||
borrowernumber => $borrower->{'borrowernumber'},
|
||||
borrowernumber => $borrower->borrowernumber,
|
||||
});
|
||||
$rs->update({uuid => $uuid_str, valid_until => $expirydate->datetime()});
|
||||
} else {
|
||||
my $rs = $schema->resultset('BorrowerPasswordRecovery')->create({
|
||||
borrowernumber=>$borrower->{'borrowernumber'},
|
||||
borrowernumber=>$borrower->borrowernumber,
|
||||
uuid => $uuid_str,
|
||||
valid_until=> $expirydate->datetime()
|
||||
});
|
||||
}
|
||||
|
||||
# create link
|
||||
my $uuidLink = $protocol . C4::Context->preference( 'OPACBaseURL' ) . "/cgi-bin/koha/opac-password-recovery.pl?uniqueKey=$uuid_str";
|
||||
my $uuidLink = C4::Context->preference( 'OPACBaseURL' ) . "/cgi-bin/koha/opac-password-recovery.pl?uniqueKey=$uuid_str";
|
||||
|
||||
# prepare the email
|
||||
my $letter = C4::Letters::GetPreparedLetter (
|
||||
module => 'members',
|
||||
letter_code => 'PASSWORD_RESET',
|
||||
branchcode => $borrower->{branchcode},
|
||||
substitute => {passwordreseturl => $uuidLink, user => $borrower->{userid} },
|
||||
branchcode => $borrower->branchcode,
|
||||
substitute => {passwordreseturl => $uuidLink, user => $borrower->userid },
|
||||
);
|
||||
|
||||
# define to/from emails
|
||||
|
|
@ -146,7 +145,7 @@ sub SendPasswordRecoveryEmail {
|
|||
|
||||
C4::Letters::EnqueueLetter( {
|
||||
letter => $letter,
|
||||
borrowernumber => $borrower->{borrowernumber},
|
||||
borrowernumber => $borrower->borrowernumber,
|
||||
to_address => $userEmail,
|
||||
from_address => $kohaEmail,
|
||||
message_transport_type => 'email',
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ use CGI;
|
|||
|
||||
use C4::Auth;
|
||||
use C4::Koha;
|
||||
use C4::Members qw(changepassword Search);
|
||||
use C4::Members qw(changepassword);
|
||||
use C4::Output;
|
||||
use C4::Context;
|
||||
use C4::Passwordrecovery qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery);
|
||||
use Koha::AuthUtils qw(hash_password);
|
||||
use Koha::Borrowers;
|
||||
my $query = new CGI;
|
||||
use HTML::Entities;
|
||||
|
||||
|
|
@ -49,17 +50,16 @@ my $errPassNotMatch;
|
|||
my $errPassTooShort;
|
||||
|
||||
if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
|
||||
my $protocol = $query->https() ? "https://" : "http://";
|
||||
#try with the main email
|
||||
$email ||= ''; # avoid undef
|
||||
my $borrower;
|
||||
my $search_results;
|
||||
# Find the borrower by his userid or email
|
||||
if( $username ){
|
||||
$search_results = Search({ userid => $username });
|
||||
$search_results = [ Koha::Borrowers->search({ userid => $username }) ];
|
||||
}
|
||||
elsif ( $email ){
|
||||
$search_results = Search({ '' => $email }, undef, undef, undef, ['emailpro', 'email', 'B_email']);
|
||||
$search_results = [ Koha::Borrowers->search({-or => {email => $email, emailpro=> $email, B_email=>$email }}) ];
|
||||
}
|
||||
if ( not $search_results ){
|
||||
$hasError = 1;
|
||||
|
|
@ -70,8 +70,8 @@ if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
|
|||
$errTooManyEmailFound = 1;
|
||||
}
|
||||
elsif( $borrower = shift @$search_results ){ # One matching borrower
|
||||
$username ||= $borrower->{'userid'};
|
||||
my @emails = ( $borrower->{'email'}, $borrower->{'emailpro'}, $borrower->{'B_email'} );
|
||||
$username ||= $borrower->userid;
|
||||
my @emails = ( $borrower->email, $borrower->emailpro, $borrower->B_email );
|
||||
# Is the given email one of the borrower's ?
|
||||
if( $email && !($email ~~ @emails) ){
|
||||
$hasError = 1;
|
||||
|
|
@ -86,7 +86,7 @@ if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
|
|||
$errNoBorrowerEmail = 1;
|
||||
}
|
||||
# Check if a password reset already issued for this borrower AND we are not asking for a new email
|
||||
elsif( ValidateBorrowernumber( $borrower->{'borrowernumber'} ) && !$query->param('resendEmail') ){
|
||||
elsif( ValidateBorrowernumber( $borrower->borrowernumber ) && !$query->param('resendEmail') ){
|
||||
$hasError = 1;
|
||||
$errAlreadyStartRecovery = 1;
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
|
|||
username => $username
|
||||
);
|
||||
}
|
||||
elsif ( SendPasswordRecoveryEmail( $borrower, $email, $protocol, $query->param('resendEmail') ) ) {#generate uuid and send recovery email
|
||||
elsif ( SendPasswordRecoveryEmail( $borrower, $email, $query->param('resendEmail') ) ) {#generate uuid and send recovery email
|
||||
$template->param(
|
||||
mail_sent => 1,
|
||||
email => $email
|
||||
|
|
|
|||
Loading…
Reference in New Issue