View | Details | Raw Unified | Return to bug 34893
Collapse All | Expand All

(-)a/C4/Auth.pm (-6 / +8 lines)
Lines 1959-1967 sub checkpw { Link Here
1959
    if ( $patron and ( $patron->account_locked )  ) {
1959
    if ( $patron and ( $patron->account_locked )  ) {
1960
        # Nothing to check, account is locked
1960
        # Nothing to check, account is locked
1961
    } elsif ($ldap && defined($password)) {
1961
    } elsif ($ldap && defined($password)) {
1962
        my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_);    # EXTERNAL AUTH
1962
        my ( $retval, $retcard, $retuserid );
1963
        ( $retval, $retcard, $retuserid, $patron ) = checkpw_ldap(@_);    # EXTERNAL AUTH
1963
        if ( $retval == 1 ) {
1964
        if ( $retval == 1 ) {
1964
            @return = ( $retval, $retcard, $retuserid );
1965
            @return = ( $retval, $retcard, $retuserid, $patron );
1965
            $passwd_ok = 1;
1966
            $passwd_ok = 1;
1966
        }
1967
        }
1967
        $check_internal_as_fallback = 1 if $retval == 0;
1968
        $check_internal_as_fallback = 1 if $retval == 0;
Lines 1971-1979 sub checkpw { Link Here
1971
        # In case of a CAS authentication, we use the ticket instead of the password
1972
        # In case of a CAS authentication, we use the ticket instead of the password
1972
        my $ticket = $query->param('ticket');
1973
        my $ticket = $query->param('ticket');
1973
        $query->delete('ticket');                                   # remove ticket to come back to original URL
1974
        $query->delete('ticket');                                   # remove ticket to come back to original URL
1974
        my ( $retval, $retcard, $retuserid, $cas_ticket ) = checkpw_cas( $ticket, $query, $type );    # EXTERNAL AUTH
1975
        my ( $retval, $retcard, $retuserid, $cas_ticket, $patron ) = checkpw_cas( $ticket, $query, $type );    # EXTERNAL AUTH
1975
        if ( $retval ) {
1976
        if ( $retval ) {
1976
            @return = ( $retval, $retcard, $retuserid, $cas_ticket );
1977
            @return = ( $retval, $retcard, $retuserid, $patron, $cas_ticket );
1977
        } else {
1978
        } else {
1978
            @return = (0);
1979
            @return = (0);
1979
        }
1980
        }
Lines 1991-1999 sub checkpw { Link Here
1991
1992
1992
        # Then, we check if it matches a valid koha user
1993
        # Then, we check if it matches a valid koha user
1993
        if ($shib_login) {
1994
        if ($shib_login) {
1994
            my ( $retval, $retcard, $retuserid ) = C4::Auth_with_shibboleth::checkpw_shib($shib_login);    # EXTERNAL AUTH
1995
            my ( $retval, $retcard, $retuserid, $patron ) = C4::Auth_with_shibboleth::checkpw_shib($shib_login);    # EXTERNAL AUTH
1995
            if ( $retval ) {
1996
            if ( $retval ) {
1996
                @return = ( $retval, $retcard, $retuserid );
1997
                @return = ( $retval, $retcard, $retuserid, $patron );
1997
            }
1998
            }
1998
            $passwd_ok = $retval;
1999
            $passwd_ok = $retval;
1999
        }
2000
        }
Lines 2004-2009 sub checkpw { Link Here
2004
    # INTERNAL AUTH
2005
    # INTERNAL AUTH
2005
    if ( $check_internal_as_fallback ) {
2006
    if ( $check_internal_as_fallback ) {
2006
        @return = checkpw_internal( $userid, $password, $no_set_userenv);
2007
        @return = checkpw_internal( $userid, $password, $no_set_userenv);
2008
        push(@return, $patron);
2007
        $passwd_ok = 1 if $return[0] > 0; # 1 or 2
2009
        $passwd_ok = 1 if $return[0] > 0; # 1 or 2
2008
    }
2010
    }
2009
2011
(-)a/C4/Auth_with_cas.pm (-10 / +6 lines)
Lines 118-134 sub checkpw_cas { Link Here
118
118
119
            # Does it match one of our users ?
119
            # Does it match one of our users ?
120
            my $dbh = C4::Context->dbh;
120
            my $dbh = C4::Context->dbh;
121
            my $sth = $dbh->prepare("select cardnumber from borrowers where userid=?");
121
            my $patron = Koha::Patrons->find({ userid => $userid });
122
            $sth->execute($userid);
122
            if ( $patron ) {
123
            if ( $sth->rows ) {
123
                return ( 1, $patron->cardnumber, $patron->userid, $ticket, $patron );
124
                $retnumber = $sth->fetchrow;
125
                return ( 1, $retnumber, $userid, $ticket );
126
            }
124
            }
127
            $sth = $dbh->prepare("select userid from borrowers where cardnumber=?");
125
            $patron = Koha::Patrons->find({ cardnumber => $userid });
128
            $sth->execute($userid);
126
            if ( $patron ) {
129
            if ( $sth->rows ) {
127
                return ( 1, $patron->cardnumber, $patron->userid, $ticket, $patron );
130
                $retnumber = $sth->fetchrow;
131
                return ( 1, $retnumber, $userid, $ticket );
132
            }
128
            }
133
129
134
            # If we reach this point, then the user is a valid CAS user, but not a Koha user
130
            # If we reach this point, then the user is a valid CAS user, but not a Koha user
(-)a/C4/Auth_with_ldap.pm (-3 / +4 lines)
Lines 204-209 sub checkpw_ldap { Link Here
204
    my (%borrower);
204
    my (%borrower);
205
	my ($borrowernumber,$cardnumber,$local_userid,$savedpw) = exists_local($userid);
205
	my ($borrowernumber,$cardnumber,$local_userid,$savedpw) = exists_local($userid);
206
206
207
    my $patron;
207
    if (( $borrowernumber and $config{update}   ) or
208
    if (( $borrowernumber and $config{update}   ) or
208
        (!$borrowernumber and $config{replicate})   ) {
209
        (!$borrowernumber and $config{replicate})   ) {
209
        %borrower = ldap_entry_2_hash($userldapentry,$userid);
210
        %borrower = ldap_entry_2_hash($userldapentry,$userid);
Lines 220-226 sub checkpw_ldap { Link Here
220
        }
221
        }
221
    } elsif ($config{replicate}) { # A2, C2
222
    } elsif ($config{replicate}) { # A2, C2
222
        my @columns = Koha::Patrons->columns;
223
        my @columns = Koha::Patrons->columns;
223
        my $patron = Koha::Patron->new(
224
        $patron = Koha::Patron->new(
224
            {
225
            {
225
                map { exists( $borrower{$_} ) ? ( $_ => $borrower{$_} ) : () } @columns
226
                map { exists( $borrower{$_} ) ? ( $_ => $borrower{$_} ) : () } @columns
226
            }
227
            }
Lines 275-281 sub checkpw_ldap { Link Here
275
            unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) {
276
            unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) {
276
                next;
277
                next;
277
            }
278
            }
278
            my $patron = Koha::Patrons->find($borrowernumber);
279
            $patron = Koha::Patrons->find($borrowernumber);
279
            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...
280
                eval {
281
                eval {
281
                    my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}});
282
                    my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}});
Lines 287-293 sub checkpw_ldap { Link Here
287
            }
288
            }
288
        }
289
        }
289
    }
290
    }
290
    return(1, $cardnumber, $userid);
291
    return(1, $cardnumber, $userid, $patron);
291
}
292
}
292
293
293
# Pass LDAP entry object and local cardnumber (userid).
294
# Pass LDAP entry object and local cardnumber (userid).
(-)a/C4/Auth_with_shibboleth.pm (-1 / +1 lines)
Lines 109-115 sub checkpw_shib { Link Here
109
        if ($config->{'sync'}) {
109
        if ($config->{'sync'}) {
110
            _sync($borrower->borrowernumber, $config, $match);
110
            _sync($borrower->borrowernumber, $config, $match);
111
        }
111
        }
112
        return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') );
112
        return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid'), $borrower );
113
    }
113
    }
114
114
115
    if ( $config->{'autocreate'} ) {
115
    if ( $config->{'autocreate'} ) {
(-)a/C4/ILSDI/Services.pm (-4 / +1 lines)
Lines 394-403 sub AuthenticatePatron { Link Here
394
    my ($cgi) = @_;
394
    my ($cgi) = @_;
395
    my $username = $cgi->param('username');
395
    my $username = $cgi->param('username');
396
    my $password = $cgi->param('password');
396
    my $password = $cgi->param('password');
397
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( $username, $password );
397
    my ($status, $cardnumber, $userid, $patron) = C4::Auth::checkpw( $username, $password );
398
    if ( $status == 1 ) {
398
    if ( $status == 1 ) {
399
        # Get the borrower
400
        my $patron = Koha::Patrons->find( { userid => $userid } );
401
        # Track the login
399
        # Track the login
402
        $patron->update_lastseen('connection');
400
        $patron->update_lastseen('connection');
403
        return { id => $patron->borrowernumber };
401
        return { id => $patron->borrowernumber };
404
- 

Return to bug 34893