From 1b4ba4167f85832cd5c2ce36fa55e5d117fde617 Mon Sep 17 00:00:00 2001 From: Johannes Barre Date: Thu, 26 Jul 2012 11:20:53 +0200 Subject: [PATCH 1/2] ' removed for Windows compatibility --- lib/simple_captcha/image.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simple_captcha/image.rb b/lib/simple_captcha/image.rb index 89eff04..fa3b785 100755 --- a/lib/simple_captcha/image.rb +++ b/lib/simple_captcha/image.rb @@ -64,14 +64,14 @@ def generate_simple_captcha_image(simple_captcha_key) #:nodoc params = ImageHelpers.image_params(SimpleCaptcha.image_style).dup params << "-size #{SimpleCaptcha.image_size}" params << "-wave #{amplitude}x#{frequency}" - params << "-gravity 'Center'" + params << "-gravity Center" params << "-pointsize 22" params << "-implode 0.2" dst = Tempfile.new(RUBY_VERSION < '1.9' ? 'simple_captcha.jpg' : ['simple_captcha', '.jpg'], SimpleCaptcha.tmp_path) dst.binmode - params << "label:#{text} '#{File.expand_path(dst.path)}'" + params << "label:#{text} #{File.expand_path(dst.path)}" SimpleCaptcha::Utils::run("convert", params.join(' ')) From b887582731fac498b97ffc4a0322b391f2ce07a1 Mon Sep 17 00:00:00 2001 From: Johannes Barre Date: Tue, 21 Aug 2012 16:09:50 +0200 Subject: [PATCH 2/2] Submit captcha_key in hidden_field_tag simple_captcha submits the captcha key (for the DB entry) in the controller based method in the session only. In the model based method, it's submitted in a hidden field. This patch submits the captcha key in a hidden field in the controller based method, too, so it works without cookies. --- lib/simple_captcha/controller.rb | 2 +- lib/simple_captcha/view.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/simple_captcha/controller.rb b/lib/simple_captcha/controller.rb index e134d98..4000f86 100644 --- a/lib/simple_captcha/controller.rb +++ b/lib/simple_captcha/controller.rb @@ -17,7 +17,7 @@ def simple_captcha_valid? return true if Rails.env.test? if params[:captcha] - data = SimpleCaptcha::Utils::simple_captcha_value(session[:captcha]) + data = SimpleCaptcha::Utils::simple_captcha_value(params[:captcha_key] || session[:captcha]) result = data == params[:captcha].delete(" ").upcase SimpleCaptcha::Utils::simple_captcha_passed!(session[:captcha]) if result return result diff --git a/lib/simple_captcha/view.rb b/lib/simple_captcha/view.rb index 53d3b9f..33e654d 100644 --- a/lib/simple_captcha/view.rb +++ b/lib/simple_captcha/view.rb @@ -72,7 +72,8 @@ def simple_captcha_field(options={}) text_field(options[:object], :captcha, :value => '', :autocomplete => 'off') + hidden_field(options[:object], :captcha_key, {:value => options[:field_value]}) else - text_field_tag(:captcha, nil, :autocomplete => 'off') + text_field_tag(:captcha, nil, :autocomplete => 'off') + + hidden_field_tag(:captcha_key, options[:field_value]) end end