From 031896d58bffda13bc24c33515e0711814dba725 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 21 May 2024 11:19:14 +0000 Subject: [PATCH] Bug 36665: (follow-up) Wrap code block in type ne 'opac' conditional Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer (cherry picked from commit fb45438ae3a95586107fdf34e03a6803714b25de) Signed-off-by: Fridolin Somers --- C4/Auth.pm | 71 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 9bd47b0059..afb9115c5c 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -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 ) ) { - - # 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; + } } } } -- 2.39.5