From 2b90dd80e746e8eca1d21ecbf5c25c768280b7d4 Mon Sep 17 00:00:00 2001 From: Blou Date: Thu, 30 Jan 2014 16:31:59 -0500 Subject: [PATCH] Improved UGLY code (sic). http://bugs.koha-community.org/show_bug.cgi?id=8753 --- opac/opac-password-recovery.pl | 50 +++++++++++++--------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/opac/opac-password-recovery.pl b/opac/opac-password-recovery.pl index 3ae4cbf..d44d19d 100755 --- a/opac/opac-password-recovery.pl +++ b/opac/opac-password-recovery.pl @@ -54,27 +54,14 @@ if ( $query->param('sendEmail') || $query->param('resendEmail') ) { #try with the main email my $borrower_number; + $email ||= ''; # avoid undef my %borrower_infos = GetMember( email => $email ); - if (%borrower_infos) { - $borrower_number = GetMember( email => $email )->{'borrowernumber'}; + %borrower_infos = GetMember( emailpro => $email ) unless %borrower_infos; + %borrower_infos = GetMember( B_email => $email ) unless %borrower_infos; + if(%borrower_infos) { + $borrower_number = $borrower_infos{'borrowernumber'}; $username = GetMemberDetails($borrower_number)->{'userid'}; } - else { - #try with the secondary email - %borrower_infos = GetMember( emailpro => $email ); - if (%borrower_infos) { - $borrower_number = GetMember( emailpro => $email )->{'borrowernumber'}; - $username = GetMemberDetails($borrower_number)->{'userid'}; - } - else { - #try when the other contact email - %borrower_infos = GetMember( B_email => $email ); - if (%borrower_infos) { - $borrower_number = GetMember( B_email => $email )->{'borrowernumber'}; - $username = GetMemberDetails($borrower_number)->{'userid'}; - } - } - } if ( !$email || !$username || !$borrower_number ) { $hasError = 1; @@ -100,22 +87,17 @@ if ( $query->param('sendEmail') || $query->param('resendEmail') ) { email => HTML::Entities::encode($email), ); } - else { - #generate uuid and send recovery email - if ( SendPasswordRecoveryEmail( $borrower_number, $email, $query ) ) { - # if it works.... - $template->param( - mail_sent => 1, - email => $email - ); - } - else { - # if it doesnt work.... - $template->param( - password_recovery => 1, - sendmailError => 1 - ); - } + elsif ( SendPasswordRecoveryEmail( $borrower_number, $email, $query ) ) {#generate uuid and send recovery email + $template->param( + mail_sent => 1, + email => $email + ); + } + else {# if it doesnt work.... + $template->param( + password_recovery => 1, + sendmailError => 1 + ); } } elsif ( $query->param('passwordReset') ) { -- 1.7.10.4