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