|
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 642-647
sub checkauth {
Link Here
|
| 642 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
634 |
my ( $userid, $cookie, $sessionID, $flags, $barshelves, $pubshelves ); |
| 643 |
my $logout = $query->param('logout.x'); |
635 |
my $logout = $query->param('logout.x'); |
| 644 |
|
636 |
|
|
|
637 |
my $anon_search_history; |
| 638 |
|
| 645 |
# This parameter is the name of the CAS server we want to authenticate against, |
639 |
# This parameter is the name of the CAS server we want to authenticate against, |
| 646 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
640 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
| 647 |
my $casparam = $query->param('cas'); |
641 |
my $casparam = $query->param('cas'); |
|
Lines 687-693
sub checkauth {
Link Here
|
| 687 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
681 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
| 688 |
#first we need to clear the anonymous session... |
682 |
#first we need to clear the anonymous session... |
| 689 |
$debug and warn "query id = " . $query->param('userid') . " but session id = " . $session->param('id'); |
683 |
$debug and warn "query id = " . $query->param('userid') . " but session id = " . $session->param('id'); |
| 690 |
$session->flush; |
684 |
$anon_search_history = $session->param('search_history'); |
|
|
685 |
$session->flush; |
| 691 |
$session->delete(); |
686 |
$session->delete(); |
| 692 |
C4::Context->_unset_userenv($sessionID); |
687 |
C4::Context->_unset_userenv($sessionID); |
| 693 |
$sessionID = undef; |
688 |
$sessionID = undef; |
|
Lines 747-752
sub checkauth {
Link Here
|
| 747 |
|
742 |
|
| 748 |
#we initiate a session prior to checking for a username to allow for anonymous sessions... |
743 |
#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()"; |
744 |
my $session = get_session("") or die "Auth ERROR: Cannot get_session()"; |
|
|
745 |
|
| 746 |
# Save anonymous search history in new session so it can be retrieved |
| 747 |
# by get_template_and_user to store it in user's search history after |
| 748 |
# a successful login. |
| 749 |
if ($anon_search_history) { |
| 750 |
$session->param('search_history', $anon_search_history); |
| 751 |
} |
| 752 |
|
| 750 |
my $sessionID = $session->id; |
753 |
my $sessionID = $session->id; |
| 751 |
C4::Context->_new_userenv($sessionID); |
754 |
C4::Context->_new_userenv($sessionID); |
| 752 |
$cookie = $query->cookie( |
755 |
$cookie = $query->cookie( |
|
Lines 953-958
sub checkauth {
Link Here
|
| 953 |
$info{'invalid_username_or_password'} = 1; |
956 |
$info{'invalid_username_or_password'} = 1; |
| 954 |
C4::Context->_unset_userenv($sessionID); |
957 |
C4::Context->_unset_userenv($sessionID); |
| 955 |
} |
958 |
} |
|
|
959 |
$session->param('lasttime',time()); |
| 960 |
$session->param('ip',$session->remote_addr()); |
| 956 |
} |
961 |
} |
| 957 |
} # END if ( $userid = $query->param('userid') ) |
962 |
} # END if ( $userid = $query->param('userid') ) |
| 958 |
elsif ($type eq "opac") { |
963 |
elsif ($type eq "opac") { |
|
Lines 1760-1775
sub getborrowernumber {
Link Here
|
| 1760 |
return 0; |
1765 |
return 0; |
| 1761 |
} |
1766 |
} |
| 1762 |
|
1767 |
|
| 1763 |
sub ParseSearchHistoryCookie { |
1768 |
sub ParseSearchHistorySession { |
| 1764 |
my $input = shift; |
1769 |
my $cgi = shift; |
| 1765 |
my $search_cookie = $input->cookie('KohaOpacRecentSearches'); |
1770 |
my $sessionID = $cgi->cookie('CGISESSID'); |
| 1766 |
return () unless $search_cookie; |
1771 |
return () unless $sessionID; |
| 1767 |
my $obj = eval { decode_json(uri_unescape($search_cookie)) }; |
1772 |
my $session = get_session($sessionID); |
|
|
1773 |
return () unless $session and $session->param('search_history'); |
| 1774 |
my $obj = eval { decode_json(uri_unescape($session->param('search_history'))) }; |
| 1768 |
return () unless defined $obj; |
1775 |
return () unless defined $obj; |
| 1769 |
return () unless ref $obj eq 'ARRAY'; |
1776 |
return () unless ref $obj eq 'ARRAY'; |
| 1770 |
return @{ $obj }; |
1777 |
return @{ $obj }; |
| 1771 |
} |
1778 |
} |
| 1772 |
|
1779 |
|
|
|
1780 |
sub SetSearchHistorySession { |
| 1781 |
my ($cgi, $search_history) = @_; |
| 1782 |
my $sessionID = $cgi->cookie('CGISESSID'); |
| 1783 |
return () unless $sessionID; |
| 1784 |
my $session = get_session($sessionID); |
| 1785 |
return () unless $session; |
| 1786 |
$session->param('search_history', uri_escape(encode_json($search_history))); |
| 1787 |
} |
| 1788 |
|
| 1773 |
END { } # module clean-up code here (global destructor) |
1789 |
END { } # module clean-up code here (global destructor) |
| 1774 |
1; |
1790 |
1; |
| 1775 |
__END__ |
1791 |
__END__ |