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

(-)a/C4/Auth.pm (-9 / +7 lines)
Lines 966-977 sub checkauth { Link Here
966
                    # doesn't have a userid. So if there is none, we pass along the
966
                    # doesn't have a userid. So if there is none, we pass along the
967
                    # borrower number, and the bits of code that need to know the user
967
                    # borrower number, and the bits of code that need to know the user
968
                    # ID will have to be smart enough to handle that.
968
                    # ID will have to be smart enough to handle that.
969
                    require C4::Members;
969
                    my $patrons = Koha::Patrons->search({ email => $value });
970
                    my @users_info = C4::Members::GetBorrowersWithEmail($value);
970
                    if ($patrons->count) {
971
                    if (@users_info) {
971
                        my $patron = $patrons->next;
972
973
                        # First the userid, then the borrowernum
972
                        # First the userid, then the borrowernum
974
                        $value = $users_info[0][1] || $users_info[0][0];
973
                        $value = $patron->userid || $patron->borrowernumber;
975
                    }
974
                    }
976
                    else {
975
                    else {
977
                        undef $value;
976
                        undef $value;
Lines 997-1008 sub checkauth { Link Here
997
                        # doesn't have a userid. So if there is none, we pass along the
996
                        # doesn't have a userid. So if there is none, we pass along the
998
                        # borrower number, and the bits of code that need to know the user
997
                        # borrower number, and the bits of code that need to know the user
999
                        # ID will have to be smart enough to handle that.
998
                        # ID will have to be smart enough to handle that.
1000
                        require C4::Members;
999
                        my $patrons = Koha::Patrons->search({ email => $value });
1001
                        my @users_info = C4::Members::GetBorrowersWithEmail($value);
1000
                        if ($patrons->count) {
1002
                        if (@users_info) {
1003
1001
1004
                            # First the userid, then the borrowernum
1002
                            # First the userid, then the borrowernum
1005
                            $value = $users_info[0][1] || $users_info[0][0];
1003
                            $value = $patron->userid || $patron->borrowernumber;
1006
                        } else {
1004
                        } else {
1007
                            undef $value;
1005
                            undef $value;
1008
                        }
1006
                        }
(-)a/C4/Members.pm (-29 lines)
Lines 85-91 BEGIN { Link Here
85
        &GetUpcomingMembershipExpires
85
        &GetUpcomingMembershipExpires
86
86
87
        &IssueSlip
87
        &IssueSlip
88
        GetBorrowersWithEmail
89
88
90
        GetOverduesForPatron
89
        GetOverduesForPatron
91
    );
90
    );
Lines 1608-1640 sub IssueSlip { Link Here
1608
    );
1607
    );
1609
}
1608
}
1610
1609
1611
=head2 GetBorrowersWithEmail
1612
1613
    ([$borrnum,$userid], ...) = GetBorrowersWithEmail('me@example.com');
1614
1615
This gets a list of users and their basic details from their email address.
1616
As it's possible for multiple user to have the same email address, it provides
1617
you with all of them. If there is no userid for the user, there will be an
1618
C<undef> there. An empty list will be returned if there are no matches.
1619
1620
=cut
1621
1622
sub GetBorrowersWithEmail {
1623
    my $email = shift;
1624
1625
    my $dbh = C4::Context->dbh;
1626
1627
    my $query = "SELECT borrowernumber, userid FROM borrowers WHERE email=?";
1628
    my $sth=$dbh->prepare($query);
1629
    $sth->execute($email);
1630
    my @result = ();
1631
    while (my $ref = $sth->fetch) {
1632
        push @result, $ref;
1633
    }
1634
    die "Failure searching for borrowers by email address: $sth->errstr" if $sth->err;
1635
    return @result;
1636
}
1637
1638
=head2 AddMember_Opac
1610
=head2 AddMember_Opac
1639
1611
1640
=cut
1612
=cut
1641
- 

Return to bug 17554