|
|
@ -83,6 +83,30 @@ sub register { |
|
|
|
my ($c, $cid) = @_; |
|
|
|
my ($c, $cid) = @_; |
|
|
|
return $self->app->db->select('captcha', '*', {cid => $cid})->hash; |
|
|
|
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 { |
|
|
|
$app->helper(add_page => sub { |
|
|
|
my ($c, $sid, $page) = @_; |
|
|
|
my ($c, $sid, $page) = @_; |
|
|
|
$self->app->db->insert('pages', { |
|
|
|
$self->app->db->insert('pages', { |
|
|
|