Commit 539cf389 authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

koha: LDAP make sure to map patron attributes from koha

parent 808ee03d
......@@ -41,10 +41,10 @@ sub DoAuth {
# auth magic here
$ldap->unbind;
if ($ldapAuth->{resultCode} == 0) {
warn "Autenticated!";
$self->{auth}->{user} = $self->processKohaPatron();
warn "Authenticated!";
$self->{auth}->{user} = $self->userToKohaPatronAttributes();
$self->{auth}->{permissions} = $self->processKohaPermissions();
$self->syncToKoha();
my $kohaPatron = $self->syncToKoha();
$self->updateSessionAuthFromKohaPatron($kohaPatron); # fetch from Koha
return $self;
} else {
......@@ -58,8 +58,8 @@ sub getAuthenticationObject {
return $self->{auth};
};
# util to map LDAP employee to patron object, need fixing
sub processKohaPatron {
# util to map LDAP employee to patron object
sub userToKohaPatronAttributes {
my ($self) = @_;
return {
categorycode => "ANS",
......@@ -96,18 +96,19 @@ sub syncToKoha {
my ($self) = @_;
warn "SYNCING USER TO KOHA";
my $patron = $self->{auth}->{user};
my $kohaPatron;
try {
my $kohaPatron = Deichman::Patron->new()->GetByUserId($patron->{email});
$kohaPatron = Deichman::Patron->new()->GetByUserId($patron->{email});
warn "UPDATING PATRON FROM LDAP";
$kohaPatron->Update($patron);
return $self;
return $kohaPatron;
} catch {
warn $_;
warn "LDAP USER NOT FOUND: ADDING NEW PATRON";
$self->addDefaultPatronAttributes();
$self->addNewKohaPatron();
$kohaPatron = $self->addNewKohaPatron();
};
return $self;
return $kohaPatron;
};
sub addDefaultPatronAttributes {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment