Bug 36665: (follow-up) Wrap code block in type ne 'opac' conditional

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit fb45438ae3)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Nick Clemens 2024-05-21 11:19:14 +00:00 committed by Fridolin Somers
parent 6f4632ef04
commit 031896d58b

View file

@ -1195,43 +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;
$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 ( $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 ) ) {
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'};
# 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;
# new op dev : add the branchname to the cookie
$branchname = $branches->{$br}->{'branchname'};
last;
}
}
}
}