Lines 49-55
BEGIN {
Link Here
|
49 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
49 |
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions); |
50 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash |
50 |
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash |
51 |
&get_all_subpermissions &get_user_subpermissions |
51 |
&get_all_subpermissions &get_user_subpermissions |
52 |
ParseSearchHistoryCookie |
52 |
ParseSearchHistorySession SetSearchHistorySession |
53 |
); |
53 |
); |
54 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
54 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
55 |
$ldap = C4::Context->config('useldapserver') || 0; |
55 |
$ldap = C4::Context->config('useldapserver') || 0; |
Lines 262-268
sub get_template_and_user {
Link Here
|
262 |
|
262 |
|
263 |
# And if there's a cookie with searches performed when the user was not logged in, |
263 |
# And if there's a cookie with searches performed when the user was not logged in, |
264 |
# we add them to the logged-in search history |
264 |
# we add them to the logged-in search history |
265 |
my @recentSearches = ParseSearchHistoryCookie($in->{'query'}); |
265 |
my @recentSearches = ParseSearchHistorySession($in->{'query'}); |
266 |
if (@recentSearches) { |
266 |
if (@recentSearches) { |
267 |
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL); |
267 |
my $sth = $dbh->prepare($SEARCH_HISTORY_INSERT_SQL); |
268 |
$sth->execute( $borrowernumber, |
268 |
$sth->execute( $borrowernumber, |
Lines 273-286
sub get_template_and_user {
Link Here
|
273 |
$_->{'time'}, |
273 |
$_->{'time'}, |
274 |
) foreach @recentSearches; |
274 |
) foreach @recentSearches; |
275 |
|
275 |
|
276 |
# And then, delete the cookie's content |
|
|
277 |
my $newsearchcookie = $in->{'query'}->cookie( |
278 |
-name => 'KohaOpacRecentSearches', |
279 |
-value => encode_json([]), |
280 |
-HttpOnly => 1, |
281 |
-expires => '' |
282 |
); |
283 |
$cookie = [$cookie, $newsearchcookie]; |
284 |
} |
276 |
} |
285 |
} |
277 |
} |
286 |
} |
278 |
} |
Lines 297-303
sub get_template_and_user {
Link Here
|
297 |
# Anonymous opac search history |
289 |
# Anonymous opac search history |
298 |
# If opac search history is enabled and at least one search has already been performed |
290 |
# If opac search history is enabled and at least one search has already been performed |
299 |
if (C4::Context->preference('EnableOpacSearchHistory')) { |
291 |
if (C4::Context->preference('EnableOpacSearchHistory')) { |
300 |
my @recentSearches = ParseSearchHistoryCookie($in->{'query'}); |
292 |
my @recentSearches = ParseSearchHistorySession($in->{'query'}); |
301 |
if (@recentSearches) { |
293 |
if (@recentSearches) { |
302 |
$template->param(ShowOpacRecentSearchLink => 1); |
294 |
$template->param(ShowOpacRecentSearchLink => 1); |
303 |
} |
295 |
} |
Lines 647-652
sub checkauth {
Link Here
|
647 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
639 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
648 |
my $logout = $query->param('logout.x'); |
640 |
my $logout = $query->param('logout.x'); |
649 |
|
641 |
|
|
|
642 |
my $anon_search_history; |
643 |
|
650 |
# This parameter is the name of the CAS server we want to authenticate against, |
644 |
# This parameter is the name of the CAS server we want to authenticate against, |
651 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
645 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
652 |
my $casparam = $query->param('cas'); |
646 |
my $casparam = $query->param('cas'); |
Lines 695-701
sub checkauth {
Link Here
|
695 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
689 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
696 |
#first we need to clear the anonymous session... |
690 |
#first we need to clear the anonymous session... |
697 |
$debug and warn "query id = $q_userid but session id = $s_userid"; |
691 |
$debug and warn "query id = $q_userid but session id = $s_userid"; |
698 |
$session->flush; |
692 |
$anon_search_history = $session->param('search_history'); |
|
|
693 |
$session->flush; |
699 |
$session->delete(); |
694 |
$session->delete(); |
700 |
C4::Context->_unset_userenv($sessionID); |
695 |
C4::Context->_unset_userenv($sessionID); |
701 |
$sessionID = undef; |
696 |
$sessionID = undef; |
Lines 755-760
sub checkauth {
Link Here
|
755 |
|
750 |
|
756 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
751 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
757 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
752 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
|
|
753 |
|
754 |
# Save anonymous search history in new session so it can be retrieved |
755 |
# by get_template_and_user to store it in user's search history after |
756 |
# a successful login. |
757 |
if ($anon_search_history) { |
758 |
$session->param('search_history', $anon_search_history); |
759 |
} |
760 |
|
758 |
my $sessionID = $session->id; |
761 |
my $sessionID = $session->id; |
759 |
C4::Context->_new_userenv($sessionID); |
762 |
C4::Context->_new_userenv($sessionID); |
760 |
$cookie = $query->cookie( |
763 |
$cookie = $query->cookie( |
Lines 966-971
sub checkauth {
Link Here
|
966 |
$info{'invalid_username_or_password'} = 1; |
969 |
$info{'invalid_username_or_password'} = 1; |
967 |
C4::Context->_unset_userenv($sessionID); |
970 |
C4::Context->_unset_userenv($sessionID); |
968 |
} |
971 |
} |
|
|
972 |
$session->param('lasttime',time()); |
973 |
$session->param('ip',$session->remote_addr()); |
969 |
} |
974 |
} |
970 |
} # END if ( $userid = $query->param('userid') ) |
975 |
} # END if ( $userid = $query->param('userid') ) |
971 |
elsif ($type eq "opac") { |
976 |
elsif ($type eq "opac") { |
Lines 1773-1788
sub getborrowernumber {
Link Here
|
1773 |
return 0; |
1778 |
return 0; |
1774 |
} |
1779 |
} |
1775 |
|
1780 |
|
1776 |
sub ParseSearchHistoryCookie { |
1781 |
sub ParseSearchHistorySession { |
1777 |
my $input = shift; |
1782 |
my $cgi = shift; |
1778 |
my $search_cookie = $input->cookie('KohaOpacRecentSearches'); |
1783 |
my $sessionID = $cgi->cookie('CGISESSID'); |
1779 |
return () unless $search_cookie; |
1784 |
return () unless $sessionID; |
1780 |
my $obj = eval { decode_json(uri_unescape($search_cookie)) }; |
1785 |
my $session = get_session($sessionID); |
|
|
1786 |
return () unless $session and $session->param('search_history'); |
1787 |
my $obj = eval { decode_json(uri_unescape($session->param('search_history'))) }; |
1781 |
return () unless defined $obj; |
1788 |
return () unless defined $obj; |
1782 |
return () unless ref $obj eq 'ARRAY'; |
1789 |
return () unless ref $obj eq 'ARRAY'; |
1783 |
return @{ $obj }; |
1790 |
return @{ $obj }; |
1784 |
} |
1791 |
} |
1785 |
|
1792 |
|
|
|
1793 |
sub SetSearchHistorySession { |
1794 |
my ($cgi, $search_history) = @_; |
1795 |
my $sessionID = $cgi->cookie('CGISESSID'); |
1796 |
return () unless $sessionID; |
1797 |
my $session = get_session($sessionID); |
1798 |
return () unless $session; |
1799 |
$session->param('search_history', uri_escape(encode_json($search_history))); |
1800 |
} |
1801 |
|
1786 |
END { } # module clean-up code here (global destructor) |
1802 |
END { } # module clean-up code here (global destructor) |
1787 |
1; |
1803 |
1; |
1788 |
__END__ |
1804 |
__END__ |