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