|
|
@ -24,7 +24,7 @@ sub captcha { |
|
|
|
} or do { |
|
|
|
} or do { |
|
|
|
chomp $@; |
|
|
|
chomp $@; |
|
|
|
$self->app->log->error("error when showing captcha: $@"); |
|
|
|
$self->app->log->error("error when showing captcha: $@"); |
|
|
|
$self->app->client_reply(500, "internal error"); |
|
|
|
$self->client_reply(500, "internal error"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ sub c_list { |
|
|
|
|
|
|
|
|
|
|
|
my $ref = $self->referrer; |
|
|
|
my $ref = $self->referrer; |
|
|
|
unless ($ref and ref($ref) eq 'HASH') { |
|
|
|
unless ($ref and ref($ref) eq 'HASH') { |
|
|
|
$self->app->client_reply(400, "can't detect referred page"); |
|
|
|
$self->client_reply(400, "can't detect referred page"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -42,20 +42,21 @@ sub c_list { |
|
|
|
if ($site and ref($site) eq 'HASH') { |
|
|
|
if ($site and ref($site) eq 'HASH') { |
|
|
|
my @cm = (); |
|
|
|
my @cm = (); |
|
|
|
if (my $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash})) { |
|
|
|
if (my $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash})) { |
|
|
|
|
|
|
|
$ref->{pid} = $pid; |
|
|
|
my @tm = $self->app->comments_by_pid($pid); |
|
|
|
my @tm = $self->app->comments_by_pid($pid); |
|
|
|
# TODO: processing |
|
|
|
# TODO: processing |
|
|
|
@cm = @tm; |
|
|
|
@cm = @tm; |
|
|
|
} |
|
|
|
} |
|
|
|
$self->render(json => \@cm); |
|
|
|
$self->render(json => \@cm); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$self->app->client_reply(400, "no such site"); |
|
|
|
$self->client_reply(400, "no such site"); |
|
|
|
} 1; |
|
|
|
} 1; |
|
|
|
} or do { |
|
|
|
} or do { |
|
|
|
chomp $@; |
|
|
|
chomp $@; |
|
|
|
my $msg = sprintf "Error when listing comments for %s/%s: %s", |
|
|
|
my $msg = sprintf "Error when listing comments for %s/%s: %s", |
|
|
|
$ref->{site}, $ref->{pid}, $@; |
|
|
|
$ref->{site}, $ref->{pid}, $@; |
|
|
|
$self->app->log->error($msg); |
|
|
|
$self->app->log->error($msg); |
|
|
|
$self->app->client_reply(500, "internal error"); |
|
|
|
$self->client_reply(500, "internal error"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -64,7 +65,7 @@ sub c_add { |
|
|
|
|
|
|
|
|
|
|
|
my $ref = $self->referrer; |
|
|
|
my $ref = $self->referrer; |
|
|
|
unless ($ref and ref($ref) eq 'HASH') { |
|
|
|
unless ($ref and ref($ref) eq 'HASH') { |
|
|
|
$self->app->client_reply(400, "can't detect referred page"); |
|
|
|
$self->client_reply(400, "can't detect referred page"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -79,25 +80,25 @@ sub c_add { |
|
|
|
} |
|
|
|
} |
|
|
|
do {{ |
|
|
|
do {{ |
|
|
|
unless ($msg{text}) { |
|
|
|
unless ($msg{text}) { |
|
|
|
$self->app->client_reply(400, "empty message"); |
|
|
|
$self->client_reply(400, "empty message"); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
my $site = $self->app->site_by_name($ref->{site}); |
|
|
|
my $site = $self->app->site_by_name($ref->{site}); |
|
|
|
unless ($site and ref($site) eq 'HASH') { |
|
|
|
unless ($site and ref($site) eq 'HASH') { |
|
|
|
$self->app->client_reply(400, "no such site"); |
|
|
|
$self->client_reply(400, "no such site"); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
if ($site->{captcha}) { |
|
|
|
if ($site->{captcha}) { |
|
|
|
unless ($cap{cid}) { |
|
|
|
unless ($cap{cid}) { |
|
|
|
$self->app->client_reply(400, "missing captcha id"); |
|
|
|
$self->client_reply(400, "missing captcha id"); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
unless ($cap{code}) { |
|
|
|
unless ($cap{code}) { |
|
|
|
$self->app->client_reply(400, "missing captcha code"); |
|
|
|
$self->client_reply(400, "missing captcha code"); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
if (my $error = $self->app->captcha_solve($cap{id}, $cap{code})) { |
|
|
|
if (my $error = $self->app->captcha_solve($cap{id}, $cap{code})) { |
|
|
|
$self->app->client_reply(400, $error); |
|
|
|
$self->client_reply(400, $error); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -113,7 +114,7 @@ sub c_add { |
|
|
|
my $msg = sprintf "Error when listing comments for %s/%s: %s", |
|
|
|
my $msg = sprintf "Error when listing comments for %s/%s: %s", |
|
|
|
$ref->{site}, $ref->{pid}, $@; |
|
|
|
$ref->{site}, $ref->{pid}, $@; |
|
|
|
$self->app->log->error($msg); |
|
|
|
$self->app->log->error($msg); |
|
|
|
$self->app->client_reply(500, "internal error"); |
|
|
|
$self->client_reply(500, "internal error"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|