sinatra-opencaptcha 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Bruno Kerrien
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ Sinatra-OpenCaptcha
2
+ ===================
3
+
4
+ A Sinatra module to seamlessly integrate OpenCaptcha to Sinatra applications.
5
+
6
+ See http://www.opencaptcha.com for more information about OpenCaptcha
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem install sinatra-captcha
12
+
13
+ Use example
14
+ -----------
15
+
16
+ require 'sinatra/base'
17
+ require 'sinatra/opencaptcha'
18
+
19
+ get '/' do
20
+ erb :index
21
+ end
22
+
23
+ post '/' do
24
+ if open_captcha_valid?
25
+ "Welcome, dear #{params[:name]}!"
26
+ else
27
+ "Go away, bloody spamming machine!"
28
+ end
29
+ end
30
+
31
+ __END__
32
+
33
+ @@ index
34
+ <html>
35
+ <head>
36
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
37
+ <title>Insert title here</title>
38
+ </head>
39
+ <body>
40
+ <form action="/" method="post">
41
+ <p><label for=\"name\">My name: </label><input type="text" id="name" name="name"/></p>
42
+ <%= open_captcha :answer_input_label => 'Votre réponse*: ', :answer_input_class => 'text' %>
43
+ <p><input type="submit" value="Submit"/></p>
44
+ </form>
45
+ </body>
46
+ </html>
@@ -0,0 +1,5 @@
1
+ <!-- OpenCaptcha [Begin] -->
2
+ <p><img src="http://www.opencaptcha.com/img/<%= image_name %>" width="<%= width %>" height=\"<%= height %>" alt="captcha"/>
3
+ <input type="hidden" name="open_captcha_image_name" value="<%= image_name %>"/></p>
4
+ <p><label for="open_captcha_answer"><%= answer_input_label %></label><input<%= answer_input_class ? " class=\"#{answer_input_class}\"" : "" %> type="text" id="open_captcha_answer" name="open_captcha_answer"/></p>
5
+ <!-- OpenCaptcha [End] -->
@@ -0,0 +1,53 @@
1
+ require 'sinatra/base'
2
+ require 'rest_client'
3
+ require 'uuidtools'
4
+
5
+ module Sinatra
6
+
7
+ # A Sinatra module to seamlessly integrate OpenCaptcha
8
+ # to Sinatra applications.
9
+ # See: http://www.opencaptcha.com
10
+ #
11
+ module OpenCaptcha
12
+
13
+ VERSION = "1.0.0"
14
+
15
+ @@default_opts = {
16
+ :width => 110,
17
+ :height => 50,
18
+ :show_answer_input => true,
19
+ :answer_input_label => 'Your answer: ',
20
+ :answer_input_class => nil
21
+ }
22
+
23
+ # A utility method to set the http proxy to be used
24
+ # for connecting to the OpenCatcha server.
25
+ #
26
+ def self.set_proxy(proxy_url)
27
+ RestClient.proxy = proxy_url
28
+ end
29
+
30
+ # Generate the html tags for inserting the OpenCaptcha image and
31
+ # (if wanted) the answer input field in the form to be protected
32
+ # against automatic spam.
33
+ #
34
+ def open_captcha(opts={})
35
+ mopts = @@default_opts.merge(opts)
36
+ mopts[:image_name] = "#{SecureRandom.hex(16)}-#{mopts[:height]}-#{mopts[:width]}.jpgx"
37
+ erb :opencaptcha, :views => File.dirname(__FILE__), :locals => mopts
38
+ end
39
+
40
+ # Check whether the user answer to the OpenCaptcha is valid or not.
41
+ # It returns 'true' if the answer is valid, otherwise 'false'.
42
+ #
43
+ def open_captcha_valid?(answer_field = :open_captcha_answer)
44
+ image_name = params[:open_captcha_image_name]
45
+ answer = params[answer_field]
46
+ RestClient.get("http://www.opencaptcha.com/validate.php?img=#{image_name}&ans=#{answer}").to_s == 'pass'
47
+ end
48
+
49
+ end
50
+
51
+ helpers OpenCaptcha
52
+
53
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module OpenCaptcha
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-opencaptcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bruno Kerrien
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: &74864040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *74864040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &74863770 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.7
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *74863770
36
+ - !ruby/object:Gem::Dependency
37
+ name: uuidtools
38
+ requirement: &74863530 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.1.2
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *74863530
47
+ description: A Sinatra module to seamlessly integrate OpenCaptcha to Sinatra applications
48
+ email:
49
+ - bruno@neirrek.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/sinatra/opencaptcha.rb
55
+ - lib/sinatra/opencaptcha_version.rb
56
+ - lib/sinatra/opencaptcha.erb
57
+ - LICENSE
58
+ - README.md
59
+ homepage: https://github.com/neirrek/sinatra-opencaptcha
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: sinatra-opencaptcha
79
+ rubygems_version: 1.8.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Sinatra extension for OpenCaptcha
83
+ test_files: []