easy_captcha 0.1.6 → 0.1.7
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/Rakefile +1 -1
- data/VERSION +1 -1
- data/easy_captcha.gemspec +3 -2
- data/lib/easy_captcha.rb +3 -0
- data/lib/easy_captcha/controller_helpers.rb +4 -4
- data/lib/easy_captcha/model_helpers.rb +26 -0
- metadata +10 -3
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gemspec|
|
7
7
|
gemspec.name = "easy_captcha"
|
8
8
|
gemspec.summary = "Captcha-Plugin for Rails"
|
9
|
-
gemspec.description = "Captcha-Plugin for Rails
|
9
|
+
gemspec.description = "Captcha-Plugin for Rails"
|
10
10
|
gemspec.email = "develop@marco-scholl.de"
|
11
11
|
gemspec.homepage = "http://github.com/traxanos/easy_captcha"
|
12
12
|
gemspec.authors = ["Marco Scholl"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/easy_captcha.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{easy_captcha}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marco Scholl"]
|
12
12
|
s.date = %q{2010-09-04}
|
13
|
-
s.description = %q{Captcha-Plugin for Rails
|
13
|
+
s.description = %q{Captcha-Plugin for Rails}
|
14
14
|
s.email = %q{develop@marco-scholl.de}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/easy_captcha/captcha.rb",
|
28
28
|
"lib/easy_captcha/controller.rb",
|
29
29
|
"lib/easy_captcha/controller_helpers.rb",
|
30
|
+
"lib/easy_captcha/model_helpers.rb",
|
30
31
|
"lib/easy_captcha/view_helpers.rb",
|
31
32
|
"resources/captcha.ttf",
|
32
33
|
"spec/easy_captcha_spec.rb",
|
data/lib/easy_captcha.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'rmagick'
|
2
2
|
require 'rails'
|
3
3
|
require 'action_controller'
|
4
|
+
require 'active_record'
|
4
5
|
|
5
6
|
# Captcha-Plugin for Rails
|
6
7
|
module EasyCaptcha
|
7
8
|
autoload :Captcha, 'easy_captcha/captcha'
|
8
9
|
autoload :Controller, 'easy_captcha/controller'
|
10
|
+
autoload :ModelHelpers, 'easy_captcha/model_helpers'
|
9
11
|
autoload :ViewHelpers, 'easy_captcha/view_helpers'
|
10
12
|
autoload :ControllerHelpers, 'easy_captcha/controller_helpers'
|
11
13
|
|
@@ -67,6 +69,7 @@ module EasyCaptcha
|
|
67
69
|
|
68
70
|
# called by rails after initialize
|
69
71
|
def init
|
72
|
+
ActiveRecord::Base.send :include, ModelHelpers
|
70
73
|
ActionController::Base.send :include, ControllerHelpers
|
71
74
|
ActionView::Base.send :include, ViewHelpers
|
72
75
|
end
|
@@ -2,18 +2,17 @@ module EasyCaptcha
|
|
2
2
|
# helper class for ActionController
|
3
3
|
module ControllerHelpers
|
4
4
|
|
5
|
-
|
6
|
-
def self.included(base)
|
5
|
+
def self.included(base) #:nodoc:
|
7
6
|
base.class_eval do
|
8
7
|
helper_method :valid_captcha?
|
9
8
|
end
|
10
9
|
end
|
11
|
-
|
10
|
+
|
12
11
|
# generate captcha image and return it as blob
|
13
12
|
def generate_captcha
|
14
13
|
Captcha.new(generate_captcha_code).image
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
# generate captcha code, save in session and return
|
18
17
|
def generate_captcha_code
|
19
18
|
session[:captcha] = EasyCaptcha.length.times.collect { EasyCaptcha.chars[rand(EasyCaptcha.chars.size)] }.join
|
@@ -23,5 +22,6 @@ module EasyCaptcha
|
|
23
22
|
def valid_captcha?(code)
|
24
23
|
session[:captcha].to_s.upcase == code.to_s.upcase
|
25
24
|
end
|
25
|
+
|
26
26
|
end
|
27
27
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EasyCaptcha
|
2
|
+
module ModelHelpers
|
3
|
+
# helper class for ActiveRecord
|
4
|
+
def self.included(base) #:nodoc:
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
# to activate model captcha validation
|
10
|
+
def acts_as_easy_captcha
|
11
|
+
include InstanceMethods
|
12
|
+
attr_writer :captcha, :captcha_verification
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def captcha
|
18
|
+
""
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_captcha?
|
22
|
+
errors.add(:captcha, :invalid) unless @captcha.to_s.upcase == @captcha_verification.to_s.upcase
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Marco Scholl
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
28
30
|
segments:
|
29
31
|
- 1
|
30
32
|
- 2
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
43
46
|
segments:
|
44
47
|
- 3
|
45
48
|
- 0
|
@@ -55,12 +58,13 @@ dependencies:
|
|
55
58
|
requirements:
|
56
59
|
- - ">="
|
57
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
58
62
|
segments:
|
59
63
|
- 0
|
60
64
|
version: "0"
|
61
65
|
type: :runtime
|
62
66
|
version_requirements: *id003
|
63
|
-
description: Captcha-Plugin for Rails
|
67
|
+
description: Captcha-Plugin for Rails
|
64
68
|
email: develop@marco-scholl.de
|
65
69
|
executables: []
|
66
70
|
|
@@ -80,6 +84,7 @@ files:
|
|
80
84
|
- lib/easy_captcha/captcha.rb
|
81
85
|
- lib/easy_captcha/controller.rb
|
82
86
|
- lib/easy_captcha/controller_helpers.rb
|
87
|
+
- lib/easy_captcha/model_helpers.rb
|
83
88
|
- lib/easy_captcha/view_helpers.rb
|
84
89
|
- resources/captcha.ttf
|
85
90
|
- spec/easy_captcha_spec.rb
|
@@ -99,6 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
104
|
requirements:
|
100
105
|
- - ">="
|
101
106
|
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
102
108
|
segments:
|
103
109
|
- 0
|
104
110
|
version: "0"
|
@@ -107,6 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
113
|
requirements:
|
108
114
|
- - ">="
|
109
115
|
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
110
117
|
segments:
|
111
118
|
- 0
|
112
119
|
version: "0"
|