Lines 147-152
sub get_template_and_user {
Link Here
|
147 |
my $borrowernumber; |
147 |
my $borrowernumber; |
148 |
my $insecure = C4::Context->preference('insecure'); |
148 |
my $insecure = C4::Context->preference('insecure'); |
149 |
if ($user or $insecure) { |
149 |
if ($user or $insecure) { |
|
|
150 |
# It's possible for $user to be the borrowernumber if they don't have a |
151 |
# userid defined (and are logging in through some other method, such |
152 |
# as SSL certs against an email address) |
153 |
$borrowernumber = getborrowernumber($user) if defined($user); |
154 |
if (!defined($borrowernumber) && defined($user)) { |
155 |
my $borrower = GetMember(borrowernumber => $user); |
156 |
if ($borrower) { |
157 |
$borrowernumber = $user; |
158 |
# A bit of a hack, but I don't know there's a nicer way |
159 |
# to do it. |
160 |
$user = $borrower->{firstname} . ' ' . $borrower->{surname}; |
161 |
} |
162 |
} |
150 |
|
163 |
|
151 |
# load the template variables for stylesheets and JavaScript |
164 |
# load the template variables for stylesheets and JavaScript |
152 |
$template->param( css_libs => $in->{'css_libs'} ); |
165 |
$template->param( css_libs => $in->{'css_libs'} ); |
Lines 177-184
sub get_template_and_user {
Link Here
|
177 |
$template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar @{$barshelves}); |
190 |
$template->param( bartotal => $total->{'bartotal'}, ) if ($total->{'bartotal'} > scalar @{$barshelves}); |
178 |
} |
191 |
} |
179 |
|
192 |
|
180 |
$borrowernumber = getborrowernumber($user) if defined($user); |
|
|
181 |
|
182 |
my ( $borr ) = GetMemberDetails( $borrowernumber ); |
193 |
my ( $borr ) = GetMemberDetails( $borrowernumber ); |
183 |
my @bordat; |
194 |
my @bordat; |
184 |
$bordat[0] = $borr; |
195 |
$bordat[0] = $borr; |
Lines 722-875
sub checkauth {
Link Here
|
722 |
} |
733 |
} |
723 |
unless ($userid || $sessionID) { |
734 |
unless ($userid || $sessionID) { |
724 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
735 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
725 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
736 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
726 |
my $sessionID = $session->id; |
737 |
my $sessionID = $session->id; |
727 |
C4::Context->_new_userenv($sessionID); |
738 |
C4::Context->_new_userenv($sessionID); |
728 |
$cookie = $query->cookie(CGISESSID => $sessionID); |
739 |
$cookie = $query->cookie(CGISESSID => $sessionID); |
729 |
$userid = $query->param('userid'); |
740 |
$userid = $query->param('userid'); |
730 |
if ($cas || $userid) { |
741 |
if ($cas || $userid || |
731 |
my $password = $query->param('password'); |
742 |
(my $pki_field = C4::Context->preference('AllowPKIAuth')) ne 'None') { |
732 |
my ($return, $cardnumber); |
743 |
my $password = $query->param('password'); |
733 |
if ($cas && $query->param('ticket')) { |
744 |
my ($return, $cardnumber); |
734 |
my $retuserid; |
745 |
if ($cas && $query->param('ticket')) { |
735 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
746 |
my $retuserid; |
736 |
$userid = $retuserid; |
747 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
737 |
$info{'invalidCasLogin'} = 1 unless ($return); |
748 |
$userid = $retuserid; |
738 |
} else { |
749 |
$info{'invalidCasLogin'} = 1 unless ($return); |
739 |
my $retuserid; |
750 |
} elsif (($pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'}) || |
740 |
( $return, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
751 |
($pki_field eq 'emailAddress' && $ENV{'SSL_CLIENT_S_DN_Email'})) { |
741 |
$userid = $retuserid if ($retuserid ne ''); |
752 |
my $value; |
742 |
} |
753 |
if ($pki_field eq 'Common Name') { |
743 |
if ($return) { |
754 |
$value = $ENV{'SSL_CLIENT_S_DN_CN'}; |
744 |
_session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime)); |
755 |
} elsif ($pki_field eq 'emailAddress') { |
745 |
if ( $flags = haspermission( $userid, $flagsrequired ) ) { |
756 |
$value = $ENV{'SSL_CLIENT_S_DN_Email'}; |
746 |
$loggedin = 1; |
757 |
# If we're looking up the email, there's a chance that the person |
747 |
} |
758 |
# doesn't have a userid. So if there is none, we pass along the |
748 |
else { |
759 |
# borrower number, and the bits of code that need to know the user |
749 |
$info{'nopermission'} = 1; |
760 |
# ID will have to be smart enough to handle that. |
750 |
C4::Context->_unset_userenv($sessionID); |
761 |
my @users_info = GetBorrowersWithEmail($value); |
751 |
} |
762 |
if (@users_info) { |
|
|
763 |
# First the userid, then the borrowernum |
764 |
$value = $users_info[0][1] || $users_info[0][0]; |
765 |
} else { |
766 |
undef $value; |
767 |
} |
768 |
} |
769 |
# 0 for no user, 1 for normal, 2 for demo user. |
770 |
$return = $value ? 1 : 0; |
771 |
$userid = $value; |
772 |
} else { |
773 |
my $retuserid; |
774 |
( $return, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
775 |
$userid = $retuserid if ($retuserid ne ''); |
776 |
} |
777 |
if ($return) { |
778 |
_session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime)); |
779 |
if ( $flags = haspermission( $userid, $flagsrequired ) ) { |
780 |
$loggedin = 1; |
781 |
} |
782 |
else { |
783 |
$info{'nopermission'} = 1; |
784 |
C4::Context->_unset_userenv($sessionID); |
785 |
} |
752 |
|
786 |
|
753 |
my ($borrowernumber, $firstname, $surname, $userflags, |
787 |
my ($borrowernumber, $firstname, $surname, $userflags, |
754 |
$branchcode, $branchname, $branchprinter, $emailaddress); |
788 |
$branchcode, $branchname, $branchprinter, $emailaddress); |
755 |
|
789 |
|
756 |
if ( $return == 1 ) { |
790 |
if ( $return == 1 ) { |
757 |
my $select = " |
791 |
my $select = " |
758 |
SELECT borrowernumber, firstname, surname, flags, borrowers.branchcode, |
792 |
SELECT borrowernumber, firstname, surname, flags, borrowers.branchcode, |
759 |
branches.branchname as branchname, |
793 |
branches.branchname as branchname, |
760 |
branches.branchprinter as branchprinter, |
794 |
branches.branchprinter as branchprinter, |
761 |
email |
795 |
email |
762 |
FROM borrowers |
796 |
FROM borrowers |
763 |
LEFT JOIN branches on borrowers.branchcode=branches.branchcode |
797 |
LEFT JOIN branches on borrowers.branchcode=branches.branchcode |
764 |
"; |
798 |
"; |
765 |
my $sth = $dbh->prepare("$select where userid=?"); |
799 |
my $sth = $dbh->prepare("$select where userid=?"); |
766 |
$sth->execute($userid); |
800 |
$sth->execute($userid); |
767 |
unless ($sth->rows) { |
801 |
unless ($sth->rows) { |
768 |
$debug and print STDERR "AUTH_1: no rows for userid='$userid'\n"; |
802 |
$debug and print STDERR "AUTH_1: no rows for userid='$userid'\n"; |
769 |
$sth = $dbh->prepare("$select where cardnumber=?"); |
803 |
$sth = $dbh->prepare("$select where cardnumber=?"); |
770 |
$sth->execute($cardnumber); |
804 |
$sth->execute($cardnumber); |
771 |
|
805 |
|
772 |
unless ($sth->rows) { |
806 |
unless ($sth->rows) { |
773 |
$debug and print STDERR "AUTH_2a: no rows for cardnumber='$cardnumber'\n"; |
807 |
$debug and print STDERR "AUTH_2a: no rows for cardnumber='$cardnumber'\n"; |
774 |
$sth->execute($userid); |
808 |
$sth->execute($userid); |
775 |
unless ($sth->rows) { |
809 |
unless ($sth->rows) { |
776 |
$debug and print STDERR "AUTH_2b: no rows for userid='$userid' AS cardnumber\n"; |
810 |
$debug and print STDERR "AUTH_2b: no rows for userid='$userid' AS cardnumber\n"; |
777 |
} |
811 |
} |
778 |
} |
812 |
} |
779 |
} |
813 |
} |
780 |
if ($sth->rows) { |
814 |
if ($sth->rows) { |
781 |
($borrowernumber, $firstname, $surname, $userflags, |
815 |
($borrowernumber, $firstname, $surname, $userflags, |
782 |
$branchcode, $branchname, $branchprinter, $emailaddress) = $sth->fetchrow; |
816 |
$branchcode, $branchname, $branchprinter, $emailaddress) = $sth->fetchrow; |
783 |
$debug and print STDERR "AUTH_3 results: " . |
817 |
$debug and print STDERR "AUTH_3 results: " . |
784 |
"$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n"; |
818 |
"$cardnumber,$borrowernumber,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress\n"; |
785 |
} else { |
819 |
} else { |
786 |
print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n"; |
820 |
print STDERR "AUTH_3: no results for userid='$userid', cardnumber='$cardnumber'.\n"; |
787 |
} |
821 |
} |
788 |
|
822 |
|
789 |
# launch a sequence to check if we have a ip for the branch, i |
823 |
# launch a sequence to check if we have a ip for the branch, i |
790 |
# if we have one we replace the branchcode of the userenv by the branch bound in the ip. |
824 |
# if we have one we replace the branchcode of the userenv by the branch bound in the ip. |
791 |
|
825 |
|
792 |
my $ip = $ENV{'REMOTE_ADDR'}; |
826 |
my $ip = $ENV{'REMOTE_ADDR'}; |
793 |
# if they specify at login, use that |
827 |
# if they specify at login, use that |
794 |
if ($query->param('branch')) { |
828 |
if ($query->param('branch')) { |
795 |
$branchcode = $query->param('branch'); |
829 |
$branchcode = $query->param('branch'); |
796 |
$branchname = GetBranchName($branchcode); |
830 |
$branchname = GetBranchName($branchcode); |
797 |
} |
831 |
} |
798 |
my $branches = GetBranches(); |
832 |
my $branches = GetBranches(); |
799 |
if (C4::Context->boolean_preference('IndependantBranches') && C4::Context->boolean_preference('Autolocation')){ |
833 |
if (C4::Context->boolean_preference('IndependantBranches') && C4::Context->boolean_preference('Autolocation')){ |
800 |
# we have to check they are coming from the right ip range |
834 |
# we have to check they are coming from the right ip range |
801 |
my $domain = $branches->{$branchcode}->{'branchip'}; |
835 |
my $domain = $branches->{$branchcode}->{'branchip'}; |
802 |
if ($ip !~ /^$domain/){ |
836 |
if ($ip !~ /^$domain/){ |
803 |
$loggedin=0; |
837 |
$loggedin=0; |
804 |
$info{'wrongip'} = 1; |
838 |
$info{'wrongip'} = 1; |
805 |
} |
839 |
} |
806 |
} |
840 |
} |
807 |
|
841 |
|
808 |
my @branchesloop; |
842 |
my @branchesloop; |
809 |
foreach my $br ( keys %$branches ) { |
843 |
foreach my $br ( keys %$branches ) { |
810 |
# now we work with the treatment of ip |
844 |
# now we work with the treatment of ip |
811 |
my $domain = $branches->{$br}->{'branchip'}; |
845 |
my $domain = $branches->{$br}->{'branchip'}; |
812 |
if ( $domain && $ip =~ /^$domain/ ) { |
846 |
if ( $domain && $ip =~ /^$domain/ ) { |
813 |
$branchcode = $branches->{$br}->{'branchcode'}; |
847 |
$branchcode = $branches->{$br}->{'branchcode'}; |
814 |
|
848 |
|
815 |
# new op dev : add the branchprinter and branchname in the cookie |
849 |
# new op dev : add the branchprinter and branchname in the cookie |
816 |
$branchprinter = $branches->{$br}->{'branchprinter'}; |
850 |
$branchprinter = $branches->{$br}->{'branchprinter'}; |
817 |
$branchname = $branches->{$br}->{'branchname'}; |
851 |
$branchname = $branches->{$br}->{'branchname'}; |
818 |
} |
852 |
} |
819 |
} |
853 |
} |
820 |
$session->param('number',$borrowernumber); |
854 |
$session->param('number',$borrowernumber); |
821 |
$session->param('id',$userid); |
855 |
$session->param('id',$userid); |
822 |
$session->param('cardnumber',$cardnumber); |
856 |
$session->param('cardnumber',$cardnumber); |
823 |
$session->param('firstname',$firstname); |
857 |
$session->param('firstname',$firstname); |
824 |
$session->param('surname',$surname); |
858 |
$session->param('surname',$surname); |
825 |
$session->param('branch',$branchcode); |
859 |
$session->param('branch',$branchcode); |
826 |
$session->param('branchname',$branchname); |
860 |
$session->param('branchname',$branchname); |
827 |
$session->param('flags',$userflags); |
861 |
$session->param('flags',$userflags); |
828 |
$session->param('emailaddress',$emailaddress); |
862 |
$session->param('emailaddress',$emailaddress); |
829 |
$session->param('ip',$session->remote_addr()); |
863 |
$session->param('ip',$session->remote_addr()); |
830 |
$session->param('lasttime',time()); |
864 |
$session->param('lasttime',time()); |
831 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; |
865 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; |
832 |
} |
866 |
} |
833 |
elsif ( $return == 2 ) { |
867 |
elsif ( $return == 2 ) { |
834 |
#We suppose the user is the superlibrarian |
868 |
#We suppose the user is the superlibrarian |
835 |
$borrowernumber = 0; |
869 |
$borrowernumber = 0; |
836 |
$session->param('number',0); |
870 |
$session->param('number',0); |
837 |
$session->param('id',C4::Context->config('user')); |
871 |
$session->param('id',C4::Context->config('user')); |
838 |
$session->param('cardnumber',C4::Context->config('user')); |
872 |
$session->param('cardnumber',C4::Context->config('user')); |
839 |
$session->param('firstname',C4::Context->config('user')); |
873 |
$session->param('firstname',C4::Context->config('user')); |
840 |
$session->param('surname',C4::Context->config('user')); |
874 |
$session->param('surname',C4::Context->config('user')); |
841 |
$session->param('branch','NO_LIBRARY_SET'); |
875 |
$session->param('branch','NO_LIBRARY_SET'); |
842 |
$session->param('branchname','NO_LIBRARY_SET'); |
876 |
$session->param('branchname','NO_LIBRARY_SET'); |
843 |
$session->param('flags',1); |
877 |
$session->param('flags',1); |
844 |
$session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress')); |
878 |
$session->param('emailaddress', C4::Context->preference('KohaAdminEmailAddress')); |
845 |
$session->param('ip',$session->remote_addr()); |
879 |
$session->param('ip',$session->remote_addr()); |
846 |
$session->param('lasttime',time()); |
880 |
$session->param('lasttime',time()); |
847 |
} |
881 |
} |
848 |
C4::Context::set_userenv( |
882 |
C4::Context::set_userenv( |
849 |
$session->param('number'), $session->param('id'), |
883 |
$session->param('number'), $session->param('id'), |
850 |
$session->param('cardnumber'), $session->param('firstname'), |
884 |
$session->param('cardnumber'), $session->param('firstname'), |
851 |
$session->param('surname'), $session->param('branch'), |
885 |
$session->param('surname'), $session->param('branch'), |
852 |
$session->param('branchname'), $session->param('flags'), |
886 |
$session->param('branchname'), $session->param('flags'), |
853 |
$session->param('emailaddress'), $session->param('branchprinter') |
887 |
$session->param('emailaddress'), $session->param('branchprinter') |
854 |
); |
888 |
); |
855 |
|
889 |
|
856 |
# Grab borrower's shelves and public shelves and add them to the session |
890 |
# Grab borrower's shelves and public shelves and add them to the session |
857 |
# $row_count determines how many records are returned from the db query |
891 |
# $row_count determines how many records are returned from the db query |
858 |
# and the number of lists to be displayed of each type in the 'Lists' button drop down |
892 |
# and the number of lists to be displayed of each type in the 'Lists' button drop down |
859 |
my $row_count = 10; # FIXME:This probably should be a syspref |
893 |
my $row_count = 10; # FIXME:This probably should be a syspref |
860 |
my ($total, $totshelves, $barshelves, $pubshelves); |
894 |
my ($total, $totshelves, $barshelves, $pubshelves); |
861 |
($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber); |
895 |
($barshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(1, $row_count, $borrowernumber); |
862 |
$total->{'bartotal'} = $totshelves; |
896 |
$total->{'bartotal'} = $totshelves; |
863 |
($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef); |
897 |
($pubshelves, $totshelves) = C4::VirtualShelves::GetRecentShelves(2, $row_count, undef); |
864 |
$total->{'pubtotal'} = $totshelves; |
898 |
$total->{'pubtotal'} = $totshelves; |
865 |
$session->param('barshelves', $barshelves); |
899 |
$session->param('barshelves', $barshelves); |
866 |
$session->param('pubshelves', $pubshelves); |
900 |
$session->param('pubshelves', $pubshelves); |
867 |
$session->param('totshelves', $total); |
901 |
$session->param('totshelves', $total); |
868 |
|
902 |
|
869 |
C4::Context::set_shelves_userenv('bar',$barshelves); |
903 |
C4::Context::set_shelves_userenv('bar',$barshelves); |
870 |
C4::Context::set_shelves_userenv('pub',$pubshelves); |
904 |
C4::Context::set_shelves_userenv('pub',$pubshelves); |
871 |
C4::Context::set_shelves_userenv('tot',$total); |
905 |
C4::Context::set_shelves_userenv('tot',$total); |
872 |
} |
906 |
} |
873 |
else { |
907 |
else { |
874 |
if ($userid) { |
908 |
if ($userid) { |
875 |
$info{'invalid_username_or_password'} = 1; |
909 |
$info{'invalid_username_or_password'} = 1; |