stupid_captcha 0.0.1
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/Gemfile +4 -0
- data/MIT-LICENSE +18 -0
- data/README.md +95 -0
- data/Rakefile +2 -0
- data/assets/backgrounds/0.png +0 -0
- data/assets/fonts/Astloch-Bold.ttf +0 -0
- data/assets/fonts/Astloch-Regular.ttf +0 -0
- data/assets/fonts/CabinSketch-Bold.ttf +0 -0
- data/assets/fonts/DawningofaNewDay.ttf +0 -0
- data/assets/fonts/Domestic_Manners.ttf +0 -0
- data/assets/fonts/JustMeAgainDownHere.ttf +0 -0
- data/assets/fonts/Kristi.ttf +0 -0
- data/assets/fonts/Meddon.ttf +0 -0
- data/assets/fonts/Megrim.ttf +0 -0
- data/assets/fonts/Miltonian-Regular.ttf +0 -0
- data/assets/fonts/OvertheRainbow.ttf +0 -0
- data/assets/fonts/PenguinAttack.ttf +0 -0
- data/assets/fonts/RuslanDisplay.ttf +0 -0
- data/assets/fonts/TSCu_Comic.ttf +0 -0
- data/assets/fonts/Tangerine_Bold.ttf +0 -0
- data/assets/fonts/Tangerine_Regular.ttf +0 -0
- data/assets/fonts/TheGirlNextDoor.ttf +0 -0
- data/assets/fonts/Vibur-Regular.ttf +0 -0
- data/assets/fonts/WaitingfortheSunrise.ttf +0 -0
- data/assets/fonts/Wallpoet-Regular.ttf +0 -0
- data/assets/fonts/default.ttf +0 -0
- data/lib/stupid_captcha/rails.rb +5 -0
- data/lib/stupid_captcha/version.rb +3 -0
- data/lib/stupid_captcha.rb +100 -0
- data/stupid_captcha.gemspec +22 -0
- metadata +108 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# about
|
2
|
+
|
3
|
+
Simple stupid captcha, use it with flash.
|
4
|
+
|
5
|
+
## how it works
|
6
|
+
1. Flash ask for captcha, for example at /captcha.json
|
7
|
+
2. get json with id and img
|
8
|
+
3. send post with data, captcha_id and captcha_input
|
9
|
+
4. validate captcha on serwer side
|
10
|
+
5. save data
|
11
|
+
|
12
|
+
# settings
|
13
|
+
|
14
|
+
create file config/stupid_captcha.rb and set StupidCaptcha settings
|
15
|
+
user rake secret to generate some goog salt
|
16
|
+
|
17
|
+
if defined?(StupidCaptcha)
|
18
|
+
StupidCaptcha.setup do |config|
|
19
|
+
# fonts path, point to directory, default GEM_RROT/assets/fonts
|
20
|
+
config.salt = "5b213328a3ed873013c553f15......."
|
21
|
+
|
22
|
+
# fonts path, point to directory, default GEM_RROT/assets/fonts
|
23
|
+
config.fonts_path = Rails.root.join('artwork/fonts').to_s
|
24
|
+
|
25
|
+
# set fonts array directly (fonts_path is not used), you can find default fonts in GEM_RROT/assets/fonts
|
26
|
+
config.fonts = [
|
27
|
+
Rails.root.join('artwork/fonts/1.ttf').to_s
|
28
|
+
]
|
29
|
+
|
30
|
+
# backgrounds path, point to directory, default GEM_RROT/assets/backgrounds
|
31
|
+
config.backgrounds_path = Rails.root.join('artwork/backgrounds').to_s
|
32
|
+
|
33
|
+
# set backgrounds array directly (backgrounds_path is not used), you can find default fonts in GEM_RROT/assets/backgrounds
|
34
|
+
config.backgrounds = [
|
35
|
+
Rails.root.join('artwork/backgrounds/1.png').to_s
|
36
|
+
]
|
37
|
+
|
38
|
+
# colors
|
39
|
+
config.colors = %w{black}
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# use it
|
45
|
+
## create captcha controller
|
46
|
+
|
47
|
+
require 'base64'
|
48
|
+
|
49
|
+
class CaptchaController < ApplicationController
|
50
|
+
def index
|
51
|
+
c = StupidCaptcha::Captcha.new
|
52
|
+
c.reset
|
53
|
+
|
54
|
+
respond_to do |wants|
|
55
|
+
wants.json do
|
56
|
+
render text: {
|
57
|
+
id: c.hash,
|
58
|
+
img: Base64.encode64(c.to_blob)
|
59
|
+
}.to_json
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
## create data controller
|
67
|
+
|
68
|
+
class DataController < ApplicationController
|
69
|
+
def create
|
70
|
+
@data = Data.new(params[:data])
|
71
|
+
|
72
|
+
respond_to do |wants|
|
73
|
+
if StupidCaptcha::Captcha.new.check(params[:captcha_id], params[:captcha_input]) && @data.save
|
74
|
+
flash[:notice] = 'Data was successfully created.'
|
75
|
+
wants.html { redirect_to(@data) }
|
76
|
+
wants.xml { render :xml => @data, :status => :created, :location => @data }
|
77
|
+
else
|
78
|
+
wants.html { render :action => "new" }
|
79
|
+
wants.xml { render :xml => @data.errors, :status => :unprocessable_entity }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
## routing
|
86
|
+
|
87
|
+
get '/captcha', :controller => "captcha", :action => 'index'
|
88
|
+
post '/data' , :controller => "data" , :action => 'create'
|
89
|
+
|
90
|
+
# Help
|
91
|
+
|
92
|
+
Looking for help?
|
93
|
+
try:
|
94
|
+
or email to me: lisukorin [at] gmail [dot] com,
|
95
|
+
don't forget write 'stupid captcha' in subject or my mail client will treat your message as spam.
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
|
3
|
+
module StupidCaptcha
|
4
|
+
GEM_ROOT = File.join(File.dirname(__FILE__), '..')
|
5
|
+
|
6
|
+
mattr_accessor :fonts_path
|
7
|
+
@@fonts_path = File.join(GEM_ROOT, 'assets/fonts').to_s
|
8
|
+
mattr_accessor :fonts
|
9
|
+
@@fonts = nil
|
10
|
+
|
11
|
+
mattr_accessor :backgrounds_path
|
12
|
+
@@backgrounds_path = File.join(GEM_ROOT, 'assets/backgrounds').to_s
|
13
|
+
mattr_accessor :backgrounds
|
14
|
+
@@backgrounds = nil
|
15
|
+
|
16
|
+
mattr_accessor :colors
|
17
|
+
@@colors = %w(black)
|
18
|
+
|
19
|
+
mattr_accessor :salt
|
20
|
+
@@salt = nil
|
21
|
+
|
22
|
+
def self.setup
|
23
|
+
yield self
|
24
|
+
end
|
25
|
+
|
26
|
+
def random_string( len = 12)
|
27
|
+
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
28
|
+
str = ""
|
29
|
+
1.upto(len) { |i| str << chars[rand(chars.size-1)] }
|
30
|
+
return str
|
31
|
+
end
|
32
|
+
|
33
|
+
def encrypt(text, salt)
|
34
|
+
Digest::SHA1.hexdigest(text+salt)
|
35
|
+
end
|
36
|
+
|
37
|
+
def fonts
|
38
|
+
@@fonts ||= files(fonts_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def backgrounds
|
42
|
+
@@backgrounds ||= files(backgrounds_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def salt
|
46
|
+
raise "StupidCaptcha.salt is blank" if @@salt.blank?
|
47
|
+
@@salt
|
48
|
+
end
|
49
|
+
|
50
|
+
def files(path)
|
51
|
+
array = []
|
52
|
+
Dir.foreach(path) do |x|
|
53
|
+
file = path+"/"+x
|
54
|
+
if File.file?(file)
|
55
|
+
array << file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return array
|
59
|
+
end
|
60
|
+
|
61
|
+
def check(hash, text)
|
62
|
+
hash.eql?(encrypt(text, salt))
|
63
|
+
end
|
64
|
+
|
65
|
+
class Captcha
|
66
|
+
include StupidCaptcha
|
67
|
+
|
68
|
+
attr_accessor :text, :img, :hash
|
69
|
+
|
70
|
+
def render
|
71
|
+
icon = Magick::Image.read(backgrounds.sample).first
|
72
|
+
|
73
|
+
drawable = Magick::Draw.new
|
74
|
+
drawable.pointsize = 32.0
|
75
|
+
drawable.font = fonts.sample
|
76
|
+
drawable.fill = colors.sample
|
77
|
+
drawable.gravity = Magick::CenterGravity
|
78
|
+
|
79
|
+
# Tweak the font to draw slightly up and left from the center
|
80
|
+
# drawable.annotate(icon, 0, 0, -3, -6, @order.quantity.to_s)
|
81
|
+
drawable.annotate(icon, 0, 0, 0,0, text)
|
82
|
+
|
83
|
+
img = icon
|
84
|
+
end
|
85
|
+
|
86
|
+
def reset
|
87
|
+
@text = random_string(rand(3)+5)
|
88
|
+
@hash = encrypt(text, salt)
|
89
|
+
@img = render
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_blob
|
93
|
+
img.to_blob
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
require 'stupid_captcha/rails'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "stupid_captcha/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "stupid_captcha"
|
7
|
+
s.version = StupidCaptcha::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rafał Lisowski"]
|
10
|
+
s.email = ["lisukorin@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/korin/stupid_captcha"
|
12
|
+
s.summary = %q{simple stupid captcha to use with flash}
|
13
|
+
s.description = %q{simple stupid captcha}
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency("rmagick", ">= 2.12.2")
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stupid_captcha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Rafa\xC5\x82 Lisowski"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-01 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rmagick
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 12
|
31
|
+
- 2
|
32
|
+
version: 2.12.2
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: simple stupid captcha
|
36
|
+
email:
|
37
|
+
- lisukorin@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- Gemfile
|
46
|
+
- MIT-LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- assets/backgrounds/0.png
|
50
|
+
- assets/fonts/Astloch-Bold.ttf
|
51
|
+
- assets/fonts/Astloch-Regular.ttf
|
52
|
+
- assets/fonts/CabinSketch-Bold.ttf
|
53
|
+
- assets/fonts/DawningofaNewDay.ttf
|
54
|
+
- assets/fonts/Domestic_Manners.ttf
|
55
|
+
- assets/fonts/JustMeAgainDownHere.ttf
|
56
|
+
- assets/fonts/Kristi.ttf
|
57
|
+
- assets/fonts/Meddon.ttf
|
58
|
+
- assets/fonts/Megrim.ttf
|
59
|
+
- assets/fonts/Miltonian-Regular.ttf
|
60
|
+
- assets/fonts/OvertheRainbow.ttf
|
61
|
+
- assets/fonts/PenguinAttack.ttf
|
62
|
+
- assets/fonts/RuslanDisplay.ttf
|
63
|
+
- assets/fonts/TSCu_Comic.ttf
|
64
|
+
- assets/fonts/Tangerine_Bold.ttf
|
65
|
+
- assets/fonts/Tangerine_Regular.ttf
|
66
|
+
- assets/fonts/TheGirlNextDoor.ttf
|
67
|
+
- assets/fonts/Vibur-Regular.ttf
|
68
|
+
- assets/fonts/WaitingfortheSunrise.ttf
|
69
|
+
- assets/fonts/Wallpoet-Regular.ttf
|
70
|
+
- assets/fonts/default.ttf
|
71
|
+
- lib/stupid_captcha.rb
|
72
|
+
- lib/stupid_captcha/rails.rb
|
73
|
+
- lib/stupid_captcha/version.rb
|
74
|
+
- stupid_captcha.gemspec
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/korin/stupid_captcha
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.7
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: simple stupid captcha to use with flash
|
107
|
+
test_files: []
|
108
|
+
|