Browse Source

* CMTD::Helpers : add 'get_captcha' and 'captcha_solve'

master
Alex 'AdUser' Z 7 years ago
parent
commit
8f528d94bd
  1. 24
      lib/CMTD/Helpers.pm

24
lib/CMTD/Helpers.pm

@ -83,6 +83,30 @@ sub register {
my ($c, $cid) = @_;
return $self->app->db->select('captcha', '*', {cid => $cid})->hash;
});
$app->helper(captcha_solve => sub {
my ($c, $id, $input) = @_;
my $cap = $self->app->db->select('captcha', '*', {cid => $id})->hash;
return "no captcha with this id"
unless $cap and ref($cap) eq 'HASH';
if ($cap->{code} ne $input) {
if ($cap->{tries} + 1 >= $app->config->{tries}) {
$app->db->delete('captcha', {id => $cap->{id}});
} else {
$app->db->update('captcha', \'tries = tries + 1', {id => $cap->{id}});
}
return "captcha code mismatch";
}
});
$app->helper(get_captcha => sub {
my ($c) = @_;
my $table = 'captcha';
my @sort = qw(shown tries);
$app->db->begin;
my ($cid, $data) = $app->db->select($table, ['id', 'data'], undef, \@sort)->list;
$app->db->update($table, {shown => time()}, {id => $cid});
$app->db->commit;
return ($cid, $data);
});
$app->helper(add_page => sub {
my ($c, $sid, $page) = @_;
$self->app->db->insert('pages', {

Loading…
Cancel
Save