Changeset 209 for captcha/trunk

Show
Ignore:
Timestamp:
05/19/06 02:20:14 (3 years ago)
Author:
ogawa
Message:

Now cache TTL setting is available.

Location:
captcha/trunk/plugins/captcha
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • captcha/trunk/plugins/captcha/captcha.pl

    r207 r209  
    1616use Authen::Captcha; 
    1717use base 'MT::Plugin'; 
    18 our $VERSION = '0.01'; 
     18our $VERSION = '0.02'; 
    1919 
    2020my $plugin = __PACKAGE__->new({ 
     
    2525    author_link => 'http://profile.typekey.com/ogawa/', 
    2626    version => $VERSION, 
     27    blog_config_template => \&config_tmpl, 
     28    settings => new MT::PluginSettings([ 
     29        ['captcha_ttl', { Default => 3600 }], 
     30    ]), 
    2731}); 
    2832MT->add_plugin($plugin); 
     
    4953    my $md5 = $q->param('captcha_md5') or return 0; 
    5054 
     55    my $ttl = config('blog:' . $blog->id)->{captcha_ttl}; 
     56    $ttl = 3600 if $ttl !~ /^\d+$/; 
     57    $captcha->expire($ttl); 
     58 
    5159    ($captcha->check_code($code, $md5) > 0) ? 1 : 0; 
    5260} 
     
    5967} 
    6068 
     69use MT::Request; 
     70sub config { 
     71    return {} unless $plugin; 
     72    my $scope = shift || 'system'; 
     73    my $r = MT::Request->instance; 
     74    my $cfg = $r->cache('captcha_config_' . $scope); 
     75    if (!$cfg) { 
     76        $cfg = $plugin->get_config_hash($scope); 
     77        $r->cache('captcha_config_' . $scope, $cfg); 
     78    } 
     79    $cfg; 
     80} 
     81 
     82sub config_tmpl { 
     83    my $tmpl = <<'EOT'; 
     84<div class="setting"> 
     85  <div class="label"><label for="captcha_ttl"><MT_TRANS phrase="CAPTCHA TTL:"></label></div> 
     86  <div class="field"> 
     87    <input name="captcha_ttl" id ="captcha_ttl" size="5" value="<TMPL_VAR NAME=CAPTCHA_TTL ESCAPE=HTML>" /> <MT_TRANS phrase="seconds"> (max: 3600 seconds) 
     88  </div> 
     89</div> 
     90EOT 
     91} 
     92 
    61931; 
  • captcha/trunk/plugins/captcha/captcha_js.cgi

    r206 r209  
    77 
    88my $captcha = Authen::Captcha->new(data_folder => './data', 
    9                                    output_folder => './images'); 
     9                                   output_folder => './images', 
     10                                   expire => 3600); 
    1011my $captcha_length = 5; 
    1112my $captcha_img_width = 25 * $captcha_length; 
  • captcha/trunk/plugins/captcha/captcha_js.fcgi

    r206 r209  
    77 
    88my $captcha = Authen::Captcha->new(data_folder => './data', 
    9                                    output_folder => './images'); 
     9                                   output_folder => './images', 
     10                                   expire => 3600); 
    1011my $captcha_length = 5; 
    1112my $captcha_img_width = 25 * $captcha_length;