Browse Source

* use new helpers, drop captcha table redefinition

master
Alex 'AdUser' Z 7 years ago
parent
commit
0008aacf02
  1. 1
      docs/cmtd.conf.sample
  2. 2
      lib/CMTD/Helpers.pm
  3. 24
      lib/CMTD/Main.pm

1
docs/cmtd.conf.sample

@ -1,7 +1,6 @@
{
db => ['dbi:SQLite:dbname=data/data.db'],
captcha => {
table => 'captcha',
tries => 5,
limit => 500,
ft_file => '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'

2
lib/CMTD/Helpers.pm

@ -36,7 +36,7 @@ sub register {
$app->helper(maintenance => sub {
my ($c) = @_;
eval {
my $table = $c->app->config->{captcha}->{table};
my $table = 'captcha';
my $tries = $c->app->config->{captcha}->{tries};
my $limit = $c->app->config->{captcha}->{limit};

24
lib/CMTD/Main.pm

@ -18,14 +18,9 @@ sub captcha {
my ($self) = @_;
eval {
my $table = $self->app->config->{captcha}->{table};
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;
my ($cid, $data) = $self->app->get_captcha;
$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 {
chomp $@;
$self->app->log->error("error when showing captcha: $@");
@ -92,18 +87,17 @@ sub c_add {
$self->app->client_reply(400, "no such site");
last;
}
if ($cap{cid}) {
unless ($cap{code}) {
$self->app->client_reply(400, "missing captcha code");
if ($site->{captcha}) {
unless ($cap{cid}) {
$self->app->client_reply(400, "missing captcha id");
last;
}
my $cap = $self->captcha_by_id($cap{cid});
unless ($cap and $cap eq 'HASH') {
$self->app->client_reply(400, "no captcha with this id");
unless ($cap{code}) {
$self->app->client_reply(400, "missing captcha code");
last;
}
unless ($cap->{code} eq $cap{code}) {
$self->app->client_reply(400, "captcha code mismatch");
if (my $error = $self->app->captcha_solve($cap{id}, $cap{code})) {
$self->app->client_reply(400, $error);
last;
}
}

Loading…
Cancel
Save