Lines 9-15
use C4::Koha;
Link Here
|
9 |
use C4::Members qw(changepassword); |
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 |
|
|
13 |
qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery); |
13 |
use Koha::AuthUtils qw(hash_password); |
14 |
use Koha::AuthUtils qw(hash_password); |
14 |
use Koha::Borrowers; |
15 |
use Koha::Borrowers; |
15 |
my $query = new CGI; |
16 |
my $query = new CGI; |
Lines 50-97
my $errPassNotMatch;
Link Here
|
50 |
my $errPassTooShort; |
51 |
my $errPassTooShort; |
51 |
|
52 |
|
52 |
if ( $query->param('sendEmail') || $query->param('resendEmail') ) { |
53 |
if ( $query->param('sendEmail') || $query->param('resendEmail') ) { |
|
|
54 |
|
53 |
#try with the main email |
55 |
#try with the main email |
54 |
$email ||= ''; # avoid undef |
56 |
$email ||= ''; # avoid undef |
55 |
my $borrower; |
57 |
my $borrower; |
56 |
my $search_results; |
58 |
my $search_results; |
|
|
59 |
|
57 |
# Find the borrower by his userid or email |
60 |
# Find the borrower by his userid or email |
58 |
if( $username ){ |
61 |
if ($username) { |
59 |
$search_results = [ Koha::Borrowers->search({ userid => $username }) ]; |
62 |
$search_results = [ Koha::Borrowers->search( { userid => $username } ) ]; |
60 |
} |
63 |
} |
61 |
elsif ( $email ){ |
64 |
elsif ($email) { |
62 |
$search_results = [ Koha::Borrowers->search({-or => {email => $email, emailpro=> $email, B_email=>$email }}) ]; |
65 |
$search_results = [ Koha::Borrowers->search( { -or => { email => $email, emailpro => $email, B_email => $email } } ) ]; |
63 |
} |
66 |
} |
64 |
if ( not $search_results ){ |
67 |
if ( not $search_results ) { |
65 |
$hasError = 1; |
68 |
$hasError = 1; |
66 |
$errNoBorrowerFound = 1; |
69 |
$errNoBorrowerFound = 1; |
67 |
} |
70 |
} |
68 |
elsif(scalar @$search_results > 1){ # Many matching borrowers |
71 |
elsif ( scalar @$search_results > 1 ) { # Many matching borrowers |
69 |
$hasError = 1; |
72 |
$hasError = 1; |
70 |
$errTooManyEmailFound = 1; |
73 |
$errTooManyEmailFound = 1; |
71 |
} |
74 |
} |
72 |
elsif( $borrower = shift @$search_results ){ # One matching borrower |
75 |
elsif ( $borrower = shift @$search_results ) { # One matching borrower |
73 |
$username ||= $borrower->userid; |
76 |
$username ||= $borrower->userid; |
74 |
my @emails = ( $borrower->email, $borrower->emailpro, $borrower->B_email ); |
77 |
my @emails = ( $borrower->email, $borrower->emailpro, $borrower->B_email ); |
|
|
78 |
|
75 |
# Is the given email one of the borrower's ? |
79 |
# Is the given email one of the borrower's ? |
76 |
if( $email && !($email ~~ @emails) ){ |
80 |
if ( $email && !( grep { $_ eq $email } @emails ) ) { |
77 |
$hasError = 1; |
81 |
$hasError = 1; |
78 |
$errBadEmail = 1; |
82 |
$errBadEmail = 1; |
79 |
} |
83 |
} |
80 |
# If we dont have an email yet. Get one of the borrower's email or raise an error. |
84 |
|
81 |
# FIXME: That ugly shift-grep contraption. |
85 |
# If we dont have an email yet. Get one of the borrower's email or raise an error. |
82 |
# $email = shift [ grep { length() } @emails ] |
86 |
# FIXME: That ugly shift-grep contraption. |
83 |
# It's supposed to get a non-empty string from the @emails array. There's surely a simpler way |
87 |
# $email = shift [ grep { length() } @emails ] |
84 |
elsif( !$email && !($email = shift [ grep { length() } @emails ]) ){ |
88 |
# It's supposed to get a non-empty string from the @emails array. There's surely a simpler way |
85 |
$hasError = 1; |
89 |
elsif ( !$email && !( $email = shift [ grep { length() } @emails ] ) ) { |
86 |
$errNoBorrowerEmail = 1; |
90 |
$hasError = 1; |
|
|
91 |
$errNoBorrowerEmail = 1; |
87 |
} |
92 |
} |
88 |
# Check if a password reset already issued for this borrower AND we are not asking for a new email |
93 |
|
89 |
elsif( ValidateBorrowernumber( $borrower->borrowernumber ) && !$query->param('resendEmail') ){ |
94 |
# Check if a password reset already issued for this borrower AND we are not asking for a new email |
|
|
95 |
elsif ( ValidateBorrowernumber( $borrower->borrowernumber ) |
96 |
&& !$query->param('resendEmail') ) |
97 |
{ |
90 |
$hasError = 1; |
98 |
$hasError = 1; |
91 |
$errAlreadyStartRecovery = 1; |
99 |
$errAlreadyStartRecovery = 1; |
92 |
} |
100 |
} |
93 |
} |
101 |
} |
94 |
else{ # 0 matching borrower |
102 |
else { # 0 matching borrower |
95 |
$hasError = 1; |
103 |
$hasError = 1; |
96 |
$errNoBorrowerFound = 1; |
104 |
$errNoBorrowerFound = 1; |
97 |
} |
105 |
} |
Lines 108-120
if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
Link Here
|
108 |
username => $username |
116 |
username => $username |
109 |
); |
117 |
); |
110 |
} |
118 |
} |
111 |
elsif ( SendPasswordRecoveryEmail( $borrower, $email, $query->param('resendEmail') ) ) {#generate uuid and send recovery email |
119 |
elsif ( SendPasswordRecoveryEmail( $borrower, $email, $query->param('resendEmail') ) ) { # generate uuid and send recovery email |
112 |
$template->param( |
120 |
$template->param( |
113 |
mail_sent => 1, |
121 |
mail_sent => 1, |
114 |
email => $email |
122 |
email => $email |
115 |
); |
123 |
); |
116 |
} |
124 |
} |
117 |
else {# if it doesn't work.... |
125 |
else { # if it doesn't work.... |
118 |
$template->param( |
126 |
$template->param( |
119 |
password_recovery => 1, |
127 |
password_recovery => 1, |
120 |
sendmailError => 1 |
128 |
sendmailError => 1 |
Lines 123-133
if ( $query->param('sendEmail') || $query->param('resendEmail') ) {
Link Here
|
123 |
} |
131 |
} |
124 |
elsif ( $query->param('passwordReset') ) { |
132 |
elsif ( $query->param('passwordReset') ) { |
125 |
( $borrower_number, $username ) = GetValidLinkInfo($uniqueKey); |
133 |
( $borrower_number, $username ) = GetValidLinkInfo($uniqueKey); |
|
|
134 |
|
126 |
#validate password length & match |
135 |
#validate password length & match |
127 |
if ( ($borrower_number) |
136 |
if ( ($borrower_number) |
128 |
&& ( $password eq $repeatPassword ) |
137 |
&& ( $password eq $repeatPassword ) |
129 |
&& ( length($password) >= $minPassLength ) ) |
138 |
&& ( length($password) >= $minPassLength ) ) |
130 |
{ #apply changes |
139 |
{ #apply changes |
131 |
changepassword( $username, $borrower_number, hash_password($password) ); |
140 |
changepassword( $username, $borrower_number, hash_password($password) ); |
132 |
CompletePasswordRecovery($uniqueKey); |
141 |
CompletePasswordRecovery($uniqueKey); |
133 |
$template->param( |
142 |
$template->param( |
Lines 135-148
elsif ( $query->param('passwordReset') ) {
Link Here
|
135 |
username => $username |
144 |
username => $username |
136 |
); |
145 |
); |
137 |
} |
146 |
} |
138 |
else { #errors |
147 |
else { #errors |
139 |
if ( !$borrower_number ) { #parameters not valid |
148 |
if ( !$borrower_number ) { #parameters not valid |
140 |
$errLinkNotValid = 1; |
149 |
$errLinkNotValid = 1; |
141 |
} |
150 |
} |
142 |
elsif ( $password ne $repeatPassword ) { #passwords does not match |
151 |
elsif ( $password ne $repeatPassword ) { #passwords does not match |
143 |
$errPassNotMatch = 1; |
152 |
$errPassNotMatch = 1; |
144 |
} |
153 |
} |
145 |
elsif ( length($password) < $minPassLength ) { #password too short |
154 |
elsif ( length($password) < $minPassLength ) { #password too short |
146 |
$errPassTooShort = 1; |
155 |
$errPassTooShort = 1; |
147 |
} |
156 |
} |
148 |
$template->param( |
157 |
$template->param( |
Lines 157-164
elsif ( $query->param('passwordReset') ) {
Link Here
|
157 |
); |
166 |
); |
158 |
} |
167 |
} |
159 |
} |
168 |
} |
160 |
elsif ($uniqueKey) { #reset password form |
169 |
elsif ($uniqueKey) { #reset password form |
161 |
#check if the link is valid |
170 |
#check if the link is valid |
162 |
( $borrower_number, $username ) = GetValidLinkInfo($uniqueKey); |
171 |
( $borrower_number, $username ) = GetValidLinkInfo($uniqueKey); |
163 |
|
172 |
|
164 |
if ( !$borrower_number ) { |
173 |
if ( !$borrower_number ) { |
Lines 171-180
elsif ($uniqueKey) { #reset password form
Link Here
|
171 |
email => $email, |
180 |
email => $email, |
172 |
uniqueKey => $uniqueKey, |
181 |
uniqueKey => $uniqueKey, |
173 |
username => $username, |
182 |
username => $username, |
174 |
errLinkNotValid => $errLinkNotValid |
183 |
errLinkNotValid => $errLinkNotValid, |
|
|
184 |
hasError => ( $errLinkNotValid ? 1 : 0 ), |
175 |
); |
185 |
); |
176 |
} |
186 |
} |
177 |
else { #password recovery form (to send email) |
187 |
else { #password recovery form (to send email) |
178 |
$template->param( password_recovery => 1 ); |
188 |
$template->param( password_recovery => 1 ); |
179 |
} |
189 |
} |
180 |
|
190 |
|