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