|
|
|
@ -86,17 +86,22 @@ sub register {
|
|
|
|
|
}); |
|
|
|
|
$app->helper(captcha_solve => sub { |
|
|
|
|
my ($c, $id, $input) = @_; |
|
|
|
|
my $cap = $c->app->db->select('captcha', '*', {cid => $id})->hash; |
|
|
|
|
my ($table, $filter) = ('captcha', {id => $id}); |
|
|
|
|
my $maxtry = $app->config->{captcha}->{tries}; |
|
|
|
|
my $cap = $c->app->db->select($table, '*', $filter)->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"; |
|
|
|
|
unless $cap and ref($cap) eq 'HASH' and $cap->{id}; |
|
|
|
|
if ($cap->{code} eq $input) { |
|
|
|
|
# captcha solved |
|
|
|
|
$app->db->delete($table, $filter); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if ($cap->{tries} + 1 >= $maxtry) { |
|
|
|
|
$app->db->delete($table, $filter); # num tries exceeded |
|
|
|
|
} else { |
|
|
|
|
$app->db->update($table, {tries => $cap->{tries} + 1}, $filter); |
|
|
|
|
} |
|
|
|
|
return "captcha code mismatch"; |
|
|
|
|
}); |
|
|
|
|
$app->helper(get_captcha => sub { |
|
|
|
|
my ($c) = @_; |
|
|
|
|