|
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; |
230 |
$patron->discard_changes; |
| 231 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
231 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
| 232 |
{ |
232 |
{ |
| 233 |
borrowernumber => $borrowernumber, |
233 |
borrowernumber => $patron->id, |
| 234 |
categorycode => $borrower{'categorycode'} |
234 |
categorycode => $borrower{'categorycode'} |
| 235 |
} |
235 |
} |
| 236 |
); |
236 |
); |
|
Lines 268-274
sub checkpw_ldap {
Link Here
|
| 268 |
} else { |
268 |
} else { |
| 269 |
return 0; # B2, D2 |
269 |
return 0; # B2, D2 |
| 270 |
} |
270 |
} |
| 271 |
if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { |
271 |
if (C4::Context->preference('ExtendedPatronAttributes') && $patron->id && ($config{update} ||$config{replicate})) { |
| 272 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
272 |
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); |
273 |
my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); |
| 274 |
while ( my $attribute_type = $attribute_types->next ) { |
274 |
while ( my $attribute_type = $attribute_types->next ) { |
|
Lines 276-282
sub checkpw_ldap {
Link Here
|
| 276 |
unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { |
276 |
unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { |
| 277 |
next; |
277 |
next; |
| 278 |
} |
278 |
} |
| 279 |
$patron = Koha::Patrons->find($borrowernumber); |
279 |
$patron = Koha::Patrons->find($patron->id); |
| 280 |
if ( $patron ) { # Should not be needed, but we are in C4::Auth LDAP... |
280 |
if ( $patron ) { # Should not be needed, but we are in C4::Auth LDAP... |
| 281 |
eval { |
281 |
eval { |
| 282 |
my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}}); |
282 |
my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}}); |
|
Lines 288-294
sub checkpw_ldap {
Link Here
|
| 288 |
} |
288 |
} |
| 289 |
} |
289 |
} |
| 290 |
} |
290 |
} |
| 291 |
return(1, $cardnumber, $userid, $patron); |
291 |
return ( 1, $patron->cardnumber, $userid, $patron ); |
| 292 |
} |
292 |
} |
| 293 |
|
293 |
|
| 294 |
# Pass LDAP entry object and local cardnumber (userid). |
294 |
# Pass LDAP entry object and local cardnumber (userid). |
|
Lines 344-366
sub ldap_entry_2_hash {
Link Here
|
| 344 |
return %borrower; |
344 |
return %borrower; |
| 345 |
} |
345 |
} |
| 346 |
|
346 |
|
| 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, |
347 |
# This function performs a password update, given the userid, borrowerid, |
| 365 |
# and digested password. It will verify that things are correct and return the |
348 |
# 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 |
349 |
# borrowers cardnumber. The idea is that it is used to keep the local |
| 367 |
- |
|
|