kaptcha 0.0.5.1 → 0.0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/core/kaptcha.rb +6 -14
- data/lib/kaptcha.rb +2 -2
- metadata +1 -1
data/lib/core/kaptcha.rb
CHANGED
@@ -10,22 +10,12 @@ module Captcha
|
|
10
10
|
|
11
11
|
def has_captcha
|
12
12
|
send(:include, InstanceMethods)
|
13
|
-
send(:after_find, :initialize_kaptcha)
|
14
13
|
end
|
15
14
|
|
16
15
|
end
|
17
16
|
|
18
17
|
module InstanceMethods
|
19
18
|
|
20
|
-
# @comment.human_captcha_desc
|
21
|
-
# %input{:type => 'text', :name => 'comment[captcha_form_result]', :autocomplete => :off, :style => 'width: 50px; display: inline;'}
|
22
|
-
# = f.hidden_field :captcha_code, :value => @comment.captcha_desc
|
23
|
-
|
24
|
-
# def __captcha__
|
25
|
-
# title = self.human_captcha_desc
|
26
|
-
# end
|
27
|
-
|
28
|
-
|
29
19
|
attr_accessor :captcha_code, :captcha_form_result
|
30
20
|
|
31
21
|
NUMBERS = (1..9).to_a
|
@@ -41,9 +31,11 @@ module Captcha
|
|
41
31
|
end
|
42
32
|
|
43
33
|
def validate
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
if new_record?
|
35
|
+
unless captcha_form_result == captcha_code
|
36
|
+
initialize_kaptcha
|
37
|
+
errors.add(:captcha_code, I18n.t('view.captcha.error_code'))
|
38
|
+
end
|
47
39
|
end
|
48
40
|
true
|
49
41
|
end
|
@@ -58,7 +50,7 @@ module Captcha
|
|
58
50
|
|
59
51
|
private
|
60
52
|
|
61
|
-
def initialize_kaptcha(params=
|
53
|
+
def initialize_kaptcha(params={})
|
62
54
|
begin
|
63
55
|
captcha_a = params[:captcha_code].split[0].to_i
|
64
56
|
rescue NoMethodError
|
data/lib/kaptcha.rb
CHANGED
@@ -2,11 +2,11 @@ require "active_record"
|
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), 'core/kaptcha')
|
4
4
|
|
5
|
-
if defined?
|
5
|
+
if defined? ActiveRecord::Base
|
6
6
|
ActiveRecord::Base.send :include, Captcha
|
7
7
|
end
|
8
8
|
|
9
9
|
if defined? I18n
|
10
|
-
I18n.load_path += Dir.glob(File.expand_path('
|
10
|
+
I18n.load_path += Dir.glob(File.expand_path('../config/locales/kaptcha.en.yml', __FILE__))
|
11
11
|
end
|
12
12
|
|