Lines 47-53
BEGIN {
Link Here
|
47 |
@ISA = qw(Exporter); |
47 |
@ISA = qw(Exporter); |
48 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
48 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
49 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &get_all_subpermissions &get_user_subpermissions |
49 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &get_all_subpermissions &get_user_subpermissions |
50 |
ParseSearchHistoryCookie |
50 |
ParseSearchHistorySession SetSearchHistorySession |
51 |
); |
51 |
); |
52 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
52 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
53 |
$ldap = C4::Context->config('useldapserver') || 0; |
53 |
$ldap = C4::Context->config('useldapserver') || 0; |
Lines 253-259
sub get_template_and_user {
Link Here
|
253 |
|
253 |
|
254 |
# And if there's a cookie with searches performed when the user was not logged in, |
254 |
# And if there's a cookie with searches performed when the user was not logged in, |
255 |
# we add them to the logged-in search history |
255 |
# we add them to the logged-in search history |
256 |
my @recentSearches = ParseSearchHistoryCookie($in->{'query'}); |
256 |
my @recentSearches = ParseSearchHistorySession($in->{'query'}); |
257 |
if (@recentSearches) { |
257 |
if (@recentSearches) { |
258 |
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL); |
258 |
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL); |
259 |
$sth->execute( $borrowernumber, |
259 |
$sth->execute( $borrowernumber, |
Lines 264-277
sub get_template_and_user {
Link Here
|
264 |
$_->{'time'}, |
264 |
$_->{'time'}, |
265 |
) foreach @recentSearches; |
265 |
) foreach @recentSearches; |
266 |
|
266 |
|
267 |
# And then, delete the cookie's content |
|
|
268 |
my $newsearchcookie = $in->{'query'}->cookie( |
269 |
-name => 'KohaOpacRecentSearches', |
270 |
-value => encode_json([]), |
271 |
-HttpOnly => 1, |
272 |
-expires => '' |
273 |
); |
274 |
$cookie = [$cookie, $newsearchcookie]; |
275 |
} |
267 |
} |
276 |
} |
268 |
} |
277 |
} |
269 |
} |
Lines 288-294
sub get_template_and_user {
Link Here
|
288 |
# Anonymous opac search history |
280 |
# Anonymous opac search history |
289 |
# If opac search history is enabled and at least one search has already been performed |
281 |
# If opac search history is enabled and at least one search has already been performed |
290 |
if (C4::Context->preference('EnableOpacSearchHistory')) { |
282 |
if (C4::Context->preference('EnableOpacSearchHistory')) { |
291 |
my @recentSearches = ParseSearchHistoryCookie($in->{'query'}); |
283 |
my @recentSearches = ParseSearchHistorySession($in->{'query'}); |
292 |
if (@recentSearches) { |
284 |
if (@recentSearches) { |
293 |
$template->param(ShowOpacRecentSearchLink => 1); |
285 |
$template->param(ShowOpacRecentSearchLink => 1); |
294 |
} |
286 |
} |
Lines 619-624
sub checkauth {
Link Here
|
619 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
611 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
620 |
my $logout = $query->param('logout.x'); |
612 |
my $logout = $query->param('logout.x'); |
621 |
|
613 |
|
|
|
614 |
my $anon_search_history; |
615 |
|
622 |
# This parameter is the name of the CAS server we want to authenticate against, |
616 |
# This parameter is the name of the CAS server we want to authenticate against, |
623 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
617 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
624 |
my $casparam = $query->param('cas'); |
618 |
my $casparam = $query->param('cas'); |
Lines 664-670
sub checkauth {
Link Here
|
664 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
658 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
665 |
#first we need to clear the anonymous session... |
659 |
#first we need to clear the anonymous session... |
666 |
$debug and warn "query id = " . $query->param('userid') . " but session id = " . $session->param('id'); |
660 |
$debug and warn "query id = " . $query->param('userid') . " but session id = " . $session->param('id'); |
667 |
$session->flush; |
661 |
$anon_search_history = $session->param('search_history'); |
|
|
662 |
$session->flush; |
668 |
$session->delete(); |
663 |
$session->delete(); |
669 |
C4::Context->_unset_userenv($sessionID); |
664 |
C4::Context->_unset_userenv($sessionID); |
670 |
$sessionID = undef; |
665 |
$sessionID = undef; |
Lines 724-729
sub checkauth {
Link Here
|
724 |
|
719 |
|
725 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
720 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
726 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
721 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
|
|
722 |
|
723 |
# Save anonymous search history in new session so it can be retrieved |
724 |
# by get_template_and_user to store it in user's search history after |
725 |
# a successful login. |
726 |
if ($anon_search_history) { |
727 |
$session->param('search_history', $anon_search_history); |
728 |
} |
729 |
|
727 |
my $sessionID = $session->id; |
730 |
my $sessionID = $session->id; |
728 |
C4::Context->_new_userenv($sessionID); |
731 |
C4::Context->_new_userenv($sessionID); |
729 |
$cookie = $query->cookie( |
732 |
$cookie = $query->cookie( |
Lines 930-935
sub checkauth {
Link Here
|
930 |
$info{'invalid_username_or_password'} = 1; |
933 |
$info{'invalid_username_or_password'} = 1; |
931 |
C4::Context->_unset_userenv($sessionID); |
934 |
C4::Context->_unset_userenv($sessionID); |
932 |
} |
935 |
} |
|
|
936 |
$session->param('lasttime',time()); |
937 |
$session->param('ip',$session->remote_addr()); |
933 |
} |
938 |
} |
934 |
} # END if ( $userid = $query->param('userid') ) |
939 |
} # END if ( $userid = $query->param('userid') ) |
935 |
elsif ($type eq "opac") { |
940 |
elsif ($type eq "opac") { |
Lines 1715-1730
sub getborrowernumber {
Link Here
|
1715 |
return 0; |
1720 |
return 0; |
1716 |
} |
1721 |
} |
1717 |
|
1722 |
|
1718 |
sub ParseSearchHistoryCookie { |
1723 |
sub ParseSearchHistorySession { |
1719 |
my $input = shift; |
1724 |
my $cgi = shift; |
1720 |
my $search_cookie = $input->cookie('KohaOpacRecentSearches'); |
1725 |
my $sessionID = $cgi->cookie('CGISESSID'); |
1721 |
return () unless $search_cookie; |
1726 |
return () unless $sessionID; |
1722 |
my $obj = eval { decode_json(uri_unescape($search_cookie)) }; |
1727 |
my $session = get_session($sessionID); |
|
|
1728 |
return () unless $session and $session->param('search_history'); |
1729 |
my $obj = eval { decode_json(uri_unescape($session->param('search_history'))) }; |
1723 |
return () unless defined $obj; |
1730 |
return () unless defined $obj; |
1724 |
return () unless ref $obj eq 'ARRAY'; |
1731 |
return () unless ref $obj eq 'ARRAY'; |
1725 |
return @{ $obj }; |
1732 |
return @{ $obj }; |
1726 |
} |
1733 |
} |
1727 |
|
1734 |
|
|
|
1735 |
sub SetSearchHistorySession { |
1736 |
my ($cgi, $search_history) = @_; |
1737 |
my $sessionID = $cgi->cookie('CGISESSID'); |
1738 |
return () unless $sessionID; |
1739 |
my $session = get_session($sessionID); |
1740 |
return () unless $session; |
1741 |
$session->param('search_history', uri_escape(encode_json($search_history))); |
1742 |
} |
1743 |
|
1728 |
END { } # module clean-up code here (global destructor) |
1744 |
END { } # module clean-up code here (global destructor) |
1729 |
1; |
1745 |
1; |
1730 |
__END__ |
1746 |
__END__ |