|
|
@ -6,7 +6,8 @@ use utf8; |
|
|
|
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
|
|
|
|
|
|
|
|
use Mojo::Util qw(trim); |
|
|
|
use Mojo::Util qw(trim b64_decode); |
|
|
|
|
|
|
|
use POSIX qw(strftime); |
|
|
|
|
|
|
|
|
|
|
|
sub index { |
|
|
|
sub index { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
@ -18,6 +19,7 @@ sub captcha { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
|
|
eval { |
|
|
|
eval { |
|
|
|
|
|
|
|
$self->allow_cors; |
|
|
|
my ($cid, $data) = $self->app->get_captcha; |
|
|
|
my ($cid, $data) = $self->app->get_captcha; |
|
|
|
$self->app->log->debug("showing captcha #$cid"); |
|
|
|
$self->app->log->debug("showing captcha #$cid"); |
|
|
|
$self->render(json => {cid => $cid, data => $data}); 1; |
|
|
|
$self->render(json => {cid => $cid, data => $data}); 1; |
|
|
@ -28,6 +30,13 @@ sub captcha { |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub c_form { |
|
|
|
|
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$self->allow_cors; |
|
|
|
|
|
|
|
$self->respond_to(json => {json => {}}, any => {template => 'main/form'}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub c_list { |
|
|
|
sub c_list { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
|
@ -38,13 +47,18 @@ sub c_list { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
eval { |
|
|
|
eval { |
|
|
|
|
|
|
|
$self->allow_cors; |
|
|
|
my $site = $self->app->site_by_name($ref->{site}); |
|
|
|
my $site = $self->app->site_by_name($ref->{site}); |
|
|
|
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; |
|
|
|
$ref->{pid} = $pid; |
|
|
|
my @tm = $self->app->comments_by_pid($pid); |
|
|
|
my @tm = $self->app->comments_by_pid($pid); |
|
|
|
# TODO: processing |
|
|
|
foreach my $c (@tm) { |
|
|
|
|
|
|
|
$c->{date} = strftime("%Y-%m-%d %H:%M", localtime($c->{date})); |
|
|
|
|
|
|
|
$c->{text} = b64_decode($c->{text}); |
|
|
|
|
|
|
|
# TODO: processing |
|
|
|
|
|
|
|
} |
|
|
|
@cm = @tm; |
|
|
|
@cm = @tm; |
|
|
|
} |
|
|
|
} |
|
|
|
$self->stash(comments => \@cm); |
|
|
|
$self->stash(comments => \@cm); |
|
|
@ -71,6 +85,7 @@ sub c_add { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
eval { |
|
|
|
eval { |
|
|
|
|
|
|
|
$self->allow_cors; |
|
|
|
my (%msg, %cap); |
|
|
|
my (%msg, %cap); |
|
|
|
$msg{addr} = $self->tx->remote_address; |
|
|
|
$msg{addr} = $self->tx->remote_address; |
|
|
|
foreach my $param (qw(name email text reply)) { |
|
|
|
foreach my $param (qw(name email text reply)) { |
|
|
@ -98,7 +113,7 @@ sub c_add { |
|
|
|
$self->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{cid}, $cap{code})) { |
|
|
|
$self->client_reply(400, $error); |
|
|
|
$self->client_reply(400, $error); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
@ -109,6 +124,7 @@ sub c_add { |
|
|
|
$pid = $self->app->pid_by_hash($site->{id}, $ref->{hash}); |
|
|
|
$pid = $self->app->pid_by_hash($site->{id}, $ref->{hash}); |
|
|
|
} |
|
|
|
} |
|
|
|
$self->add_comment($pid, \%msg); |
|
|
|
$self->add_comment($pid, \%msg); |
|
|
|
|
|
|
|
$self->client_reply(200, "OK"); |
|
|
|
}} while (0); 1; |
|
|
|
}} while (0); 1; |
|
|
|
} or do { |
|
|
|
} or do { |
|
|
|
chomp $@; |
|
|
|
chomp $@; |
|
|
|