From a948571bc063be59274405d31eff1a2e18651fc4 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Tue, 22 Aug 2017 16:55:28 +1000 Subject: [PATCH] + /captcha --- lib/CMTD/Main.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/CMTD/Main.pm b/lib/CMTD/Main.pm index 5ffd21e..21fbe3c 100644 --- a/lib/CMTD/Main.pm +++ b/lib/CMTD/Main.pm @@ -13,6 +13,23 @@ sub index { } sub captcha { + my ($self) = @_; + + eval { + my $table = $c->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; + $self->app->log->debug("showing captcha #$cid"); + $self->render(json => {id => $cid, data => $data}); 1; + } or do { + chomp $@; + $self->app->log->error("error when showing captcha: $@"); + $self->res->code(500); + $self->render(text => 'internal error'); + }; } sub c_list {