|
|
|
@ -5,6 +5,7 @@ use warnings;
|
|
|
|
|
use utf8; |
|
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
|
|
use Mojo::Util qw(b64_encode); |
|
|
|
|
|
|
|
|
|
sub register { |
|
|
|
|
my ($self, $app) = @_; |
|
|
|
@ -31,6 +32,32 @@ sub register {
|
|
|
|
|
|
|
|
|
|
return {site => $site, pid => $md5, path => $path}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$app->helper(maintenance => sub { |
|
|
|
|
my ($c) = @_; |
|
|
|
|
eval { |
|
|
|
|
my $table = $c->app->config->{captcha}->{table}; |
|
|
|
|
my $tries = $c->app->config->{captcha}->{tries}; |
|
|
|
|
my $limit = $c->app->config->{captcha}->{limit}; |
|
|
|
|
|
|
|
|
|
$c->app->db->delete($table, {tries => {'>=' => $tries}}); |
|
|
|
|
my $count = $c->app->db->select($table, 'count(id)')->list; |
|
|
|
|
if ($count < $limit) { |
|
|
|
|
$c->app->db->begin; |
|
|
|
|
foreach my $n ($count + 1 .. $limit) { |
|
|
|
|
$c->app->log->info("generating captcha's: $n of $limit"); |
|
|
|
|
my ($code, $data) = $c->app->captcha->create; |
|
|
|
|
next unless $code and $data; |
|
|
|
|
my $b64 = 'data:image/jpeg;base64,' . b64_encode($data, ''); |
|
|
|
|
$c->app->db->insert($table, { code => $code, data => $b64 }); |
|
|
|
|
} |
|
|
|
|
$c->app->db->commit; |
|
|
|
|
} 1; |
|
|
|
|
} or do { |
|
|
|
|
chomp $@; |
|
|
|
|
$c->app->log->error($@); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
1; |
|
|
|
|