Lines 332-363
Others will be added here depending on the needs (for instance biblio does not e
Link Here
|
332 |
sub output_and_exit_if_error { |
332 |
sub output_and_exit_if_error { |
333 |
my ( $query, $cookie, $template, $params ) = @_; |
333 |
my ( $query, $cookie, $template, $params ) = @_; |
334 |
my $error; |
334 |
my $error; |
335 |
if ($params->{module} eq 'CSRF_TOKEN_CHECK') { |
335 |
if ( $params and exists $params->{module} ) { |
336 |
my $csrfcheck = Koha::Token->new->check_csrf( { |
336 |
if ( $params->{module} eq 'members' ) { |
337 |
session_id => scalar $cookie, |
337 |
my $logged_in_user = $params->{logged_in_user}; |
338 |
token => scalar $params->{csrf_token}, |
338 |
my $current_patron = $params->{current_patron}; |
339 |
}); |
339 |
if ( not $current_patron ) { |
340 |
unless ($csrfcheck) { |
340 |
$error = 'unknown_patron'; |
341 |
$error = 'wrong_csrf_token'; |
341 |
} |
342 |
} |
342 |
elsif ( not $logged_in_user->can_see_patron_infos($current_patron) ) |
343 |
|
343 |
{ |
344 |
} else { |
344 |
$error = 'cannot_see_patron_infos'; |
345 |
if ( $params and exists $params->{module} ) { |
|
|
346 |
if ( $params->{module} eq 'members' ) { |
347 |
my $logged_in_user = $params->{logged_in_user}; |
348 |
my $current_patron = $params->{current_patron}; |
349 |
if ( not $current_patron ) { |
350 |
$error = 'unknown_patron'; |
351 |
} |
352 |
elsif( not $logged_in_user->can_see_patron_infos( $current_patron ) ) { |
353 |
$error = 'cannot_see_patron_infos'; |
354 |
} |
355 |
} |
345 |
} |
356 |
} elsif ( $params->{module} eq 'cataloguing' ) { |
346 |
} |
|
|
347 |
elsif ( $params->{module} eq 'cataloguing' ) { |
357 |
# We are testing the record to avoid additem to fetch the Koha::Biblio |
348 |
# We are testing the record to avoid additem to fetch the Koha::Biblio |
358 |
# But in the long term we will want to get a biblio in parameter |
349 |
# But in the long term we will want to get a biblio in parameter |
359 |
$error = 'unknown_biblio' unless $params->{record}; |
350 |
$error = 'unknown_biblio' unless $params->{record}; |
360 |
} |
351 |
} |
|
|
352 |
elsif ( $params->{module} eq 'CSRF_TOKEN_CHECK' ) { |
353 |
$error = 'wrong_csrf_token' |
354 |
unless Koha::Token->new->check_csrf( |
355 |
{ |
356 |
session_id => scalar $query->cookie('CGISESSID'), |
357 |
token => scalar $query->param('csrf_token'), |
358 |
} |
359 |
); |
360 |
} |
361 |
} |
361 |
} |
362 |
} |
362 |
output_and_exit( $query, $cookie, $template, $error ) if $error; |
363 |
output_and_exit( $query, $cookie, $template, $error ) if $error; |
363 |
return; |
364 |
return; |