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 {