Lines 202-223
sub checkpw_ldap {
Link Here
|
202 |
# But we still have work to do. See perldoc below for detailed breakdown. |
202 |
# But we still have work to do. See perldoc below for detailed breakdown. |
203 |
|
203 |
|
204 |
my (%borrower); |
204 |
my (%borrower); |
205 |
my ($borrowernumber,$cardnumber,$local_userid,$savedpw) = exists_local($userid); |
205 |
my $patron = Koha::Patrons->find( { userid => $userid } ) || Koha::Patrons->find( { cardnumber => $userid } ); |
206 |
|
206 |
|
207 |
my $patron; |
207 |
if (( $patron and $config{update} ) or |
208 |
if (( $borrowernumber and $config{update} ) or |
208 |
(!$patron and $config{replicate}) ) { |
209 |
(!$borrowernumber and $config{replicate}) ) { |
209 |
my $cardnumber = $patron ? $patron->cardnumber : q{}; |
210 |
%borrower = ldap_entry_2_hash($userldapentry,$cardnumber); |
210 |
%borrower = ldap_entry_2_hash($userldapentry,$cardnumber); |
211 |
#warn "checkpw_ldap received \%borrower w/ " . keys(%borrower), " keys: ", join(' ', keys %borrower), "\n"; |
|
|
212 |
} |
211 |
} |
213 |
|
212 |
|
214 |
if ($borrowernumber) { |
213 |
if ($patron) { |
215 |
if ($config{update}) { # A1, B1 |
214 |
if ( $config{update} ) { # A1, B1 |
216 |
my $c2 = &update_local($local_userid,$password,$borrowernumber,\%borrower) || ''; |
215 |
my $c2 = &update_local( $patron->userid, $password, $patron->id, \%borrower ) || ''; |
217 |
($cardnumber eq $c2) or warn "update_local returned cardnumber '$c2' instead of '$cardnumber'"; |
216 |
( $patron->cardnumber eq $c2 ) |
218 |
} else { # C1, D1 |
217 |
or warn "update_local returned cardnumber '$c2' instead of '$patron->cardnumber'"; |
219 |
# maybe update just the password? |
218 |
} else { # C1, D1 |
220 |
return(1, $cardnumber, $local_userid); |
219 |
# maybe update just the password? |
|
|
220 |
return ( 1, $patron->cardnumber, $patron->userid, $patron ); |
221 |
} |
221 |
} |
222 |
} elsif ($config{replicate}) { # A2, C2 |
222 |
} elsif ($config{replicate}) { # A2, C2 |
223 |
my @columns = Koha::Patrons->columns; |
223 |
my @columns = Koha::Patrons->columns; |
Lines 227-236
sub checkpw_ldap {
Link Here
|
227 |
} |
227 |
} |
228 |
)->store; |
228 |
)->store; |
229 |
die "Insert of new patron failed" unless $patron; |
229 |
die "Insert of new patron failed" unless $patron; |
230 |
$borrowernumber = $patron->borrowernumber; |
|
|
231 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
230 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
232 |
{ |
231 |
{ |
233 |
borrowernumber => $borrowernumber, |
232 |
borrowernumber => $patron->id, |
234 |
categorycode => $borrower{'categorycode'} |
233 |
categorycode => $borrower{'categorycode'} |
235 |
} |
234 |
} |
236 |
); |
235 |
); |
Lines 268-274
sub checkpw_ldap {
Link Here
|
268 |
} else { |
267 |
} else { |
269 |
return 0; # B2, D2 |
268 |
return 0; # B2, D2 |
270 |
} |
269 |
} |
271 |
if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { |
270 |
if (C4::Context->preference('ExtendedPatronAttributes') && $patron->id && ($config{update} ||$config{replicate})) { |
272 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
271 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
273 |
my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); |
272 |
my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); |
274 |
while ( my $attribute_type = $attribute_types->next ) { |
273 |
while ( my $attribute_type = $attribute_types->next ) { |
Lines 276-282
sub checkpw_ldap {
Link Here
|
276 |
unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { |
275 |
unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { |
277 |
next; |
276 |
next; |
278 |
} |
277 |
} |
279 |
$patron = Koha::Patrons->find($borrowernumber); |
278 |
$patron = Koha::Patrons->find($patron->id); |
280 |
if ( $patron ) { # Should not be needed, but we are in C4::Auth LDAP... |
279 |
if ( $patron ) { # Should not be needed, but we are in C4::Auth LDAP... |
281 |
eval { |
280 |
eval { |
282 |
my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}}); |
281 |
my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}}); |
Lines 288-294
sub checkpw_ldap {
Link Here
|
288 |
} |
287 |
} |
289 |
} |
288 |
} |
290 |
} |
289 |
} |
291 |
return(1, $cardnumber, $userid, $patron); |
290 |
return ( 1, $patron->cardnumber, $userid, $patron ); |
292 |
} |
291 |
} |
293 |
|
292 |
|
294 |
# Pass LDAP entry object and local cardnumber (userid). |
293 |
# Pass LDAP entry object and local cardnumber (userid). |
Lines 344-366
sub ldap_entry_2_hash {
Link Here
|
344 |
return %borrower; |
343 |
return %borrower; |
345 |
} |
344 |
} |
346 |
|
345 |
|
347 |
sub exists_local { |
|
|
348 |
my $arg = shift; |
349 |
my $dbh = C4::Context->dbh; |
350 |
my $select = "SELECT borrowernumber,cardnumber,userid,password FROM borrowers "; |
351 |
|
352 |
my $sth = $dbh->prepare("$select WHERE userid=?"); # was cardnumber=? |
353 |
$sth->execute($arg); |
354 |
#warn "Userid '$arg' exists_local? %s\n", $sth->rows; |
355 |
($sth->rows == 1) and return $sth->fetchrow; |
356 |
|
357 |
$sth = $dbh->prepare("$select WHERE cardnumber=?"); |
358 |
$sth->execute($arg); |
359 |
#warn "Cardnumber '$arg' exists_local? %s\n", $sth->rows; |
360 |
($sth->rows == 1) and return $sth->fetchrow; |
361 |
return 0; |
362 |
} |
363 |
|
364 |
# This function performs a password update, given the userid, borrowerid, |
346 |
# This function performs a password update, given the userid, borrowerid, |
365 |
# and digested password. It will verify that things are correct and return the |
347 |
# and digested password. It will verify that things are correct and return the |
366 |
# borrowers cardnumber. The idea is that it is used to keep the local |
348 |
# borrowers cardnumber. The idea is that it is used to keep the local |
367 |
- |
|
|