|
|
@ -18,14 +18,9 @@ sub captcha { |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
|
|
eval { |
|
|
|
eval { |
|
|
|
my $table = $self->app->config->{captcha}->{table}; |
|
|
|
my ($cid, $data) = $self->app->get_captcha; |
|
|
|
my @sort = qw(shown tries); |
|
|
|
|
|
|
|
$self->app->db->begin; |
|
|
|
|
|
|
|
my ($cid, $data) = $self->app->db->select($table, ['id', 'data'], undef, \@sort)->list; |
|
|
|
|
|
|
|
$self->app->db->update($table, {shown => time()}, {id => $cid}); |
|
|
|
|
|
|
|
$self->app->db->commit; |
|
|
|
|
|
|
|
$self->app->log->debug("showing captcha #$cid"); |
|
|
|
$self->app->log->debug("showing captcha #$cid"); |
|
|
|
$self->render(json => {id => $cid, data => $data}); 1; |
|
|
|
$self->render(json => {cid => $cid, data => $data}); 1; |
|
|
|
} or do { |
|
|
|
} or do { |
|
|
|
chomp $@; |
|
|
|
chomp $@; |
|
|
|
$self->app->log->error("error when showing captcha: $@"); |
|
|
|
$self->app->log->error("error when showing captcha: $@"); |
|
|
@ -92,18 +87,17 @@ sub c_add { |
|
|
|
$self->app->client_reply(400, "no such site"); |
|
|
|
$self->app->client_reply(400, "no such site"); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
if ($cap{cid}) { |
|
|
|
if ($site->{captcha}) { |
|
|
|
unless ($cap{code}) { |
|
|
|
unless ($cap{cid}) { |
|
|
|
$self->app->client_reply(400, "missing captcha code"); |
|
|
|
$self->app->client_reply(400, "missing captcha id"); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
my $cap = $self->captcha_by_id($cap{cid}); |
|
|
|
unless ($cap{code}) { |
|
|
|
unless ($cap and $cap eq 'HASH') { |
|
|
|
$self->app->client_reply(400, "missing captcha code"); |
|
|
|
$self->app->client_reply(400, "no captcha with this id"); |
|
|
|
|
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
unless ($cap->{code} eq $cap{code}) { |
|
|
|
if (my $error = $self->app->captcha_solve($cap{id}, $cap{code})) { |
|
|
|
$self->app->client_reply(400, "captcha code mismatch"); |
|
|
|
$self->app->client_reply(400, $error); |
|
|
|
last; |
|
|
|
last; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|