Skip to content

Commit

Permalink
CUYAHOGA - Bug 36665: (follow-up) Wrap code block in type ne 'opac' c…
Browse files Browse the repository at this point in the history
…onditional

Signed-off-by: Jonathan Druart <[email protected]>
  • Loading branch information
kidclamp authored and kylemhall committed May 22, 2024
1 parent 724e59d commit 8927269
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions C4/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1195,42 +1195,44 @@ sub checkauth {
$register_name = $register->name if ($register);
}
my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search->as_list };
if ( $type ne 'opac' and C4::Context->preference('AutoLocation') ) {

# we have to check they are coming from the right ip range
my $domain = $branches->{$branchcode}->{'branchip'};
$domain =~ s|\.\*||g;
if ( $ip !~ /^$domain/ ) {
$cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
-name => 'CGISESSID',
-value => '',
-HttpOnly => 1,
-secure => ( C4::Context->https_enabled() ? 1 : 0 ),
-sameSite => 'Lax',
));
$info{'wrongip'} = 1;
$auth_state = "failed";
if ( $type ne 'opac' ) {
if ( C4::Context->preference('AutoLocation') ) {
# we have to check they are coming from the right ip range
my $domain = $branches->{$branchcode}->{'branchip'};
$domain =~ s|\.\*||g;
$domain =~ s/\s+//g;
if ( $ip !~ /^$domain/ ) {
$cookie = $cookie_mgr->replace_in_list( $cookie, $query->cookie(
-name => 'CGISESSID',
-value => '',
-HttpOnly => 1,
-secure => ( C4::Context->https_enabled() ? 1 : 0 ),
-sameSite => 'Lax',
));
$info{'wrongip'} = 1;
$auth_state = "failed";
}
}
}

if (
(
!C4::Context->preference('AutoLocation')
&& C4::Context->preference('StaffLoginBranchBasedOnIP')
)
|| ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' )
)
{
foreach my $br ( uniq( $branchcode, keys %$branches ) ) {

# now we work with the treatment of ip
my $domain = $branches->{$br}->{'branchip'};
if ( $domain && $ip =~ /^$domain/ ) {
$branchcode = $branches->{$br}->{'branchcode'};

# new op dev : add the branchname to the cookie
$branchname = $branches->{$br}->{'branchname'};
last;
if (
(
!C4::Context->preference('AutoLocation')
&& C4::Context->preference('StaffLoginBranchBasedOnIP')
)
|| ( C4::Context->preference('AutoLocation') && $auth_state ne 'failed' )
)
{
foreach my $br ( uniq( $branchcode, keys %$branches ) ) {

# now we work with the treatment of ip
my $domain = $branches->{$br}->{'branchip'};
if ( $domain && $ip =~ /^$domain/ ) {
$branchcode = $branches->{$br}->{'branchcode'};

# new op dev : add the branchname to the cookie
$branchname = $branches->{$br}->{'branchname'};
last;
}
}
}
}
Expand Down

0 comments on commit 8927269

Please sign in to comment.