idi_captcha 1.1.0 โ 2.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.
- checksums.yaml +4 -4
- data/README.md +9 -101
- data/idi_captcha.gemspec +0 -2
- data/lib/idi_captcha/captcha.rb +5 -29
- data/lib/idi_captcha/helpers/view_helper.rb +5 -1
- data/lib/idi_captcha/version.rb +1 -1
- data/lib/idi_captcha.rb +0 -6
- metadata +2 -24
- data/app/controllers/idi_captcha/captcha_controller.rb +0 -11
- data/config/routes.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45261bbd789a3d888a5f1ae4991c361a3001705e07d999f0e7ed7b643c71f8df
|
4
|
+
data.tar.gz: '059687e5cf34b5182623d0311a76e9db8499adf50513902309cdc322f6c90b48'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9a0bfeb032f330c3d384ee981ef1c59afb6ea3c8b57e552e87c37f64bbaf7e5cdc5576a13a332d6d23222dfc180cec425b910c111d52ee1b5e44e2d862a6ed6
|
7
|
+
data.tar.gz: 46eaf910b294d099489861a0481098d2ec81b74ec8bb58f609f52d712ba7c9dec60479f3362df5b1ba6b2770752561fc48f3883c17632663adc361fba4316072
|
data/README.md
CHANGED
@@ -2,115 +2,23 @@
|
|
2
2
|
|
3
3
|
Offline CAPTCHA for Rails 6+ applications that works without any external service. Fully compatible with Devise and designed for restricted or offline environments.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
Add this line to your application's **Gemfile**:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'idi_captcha', path: 'relative/path/to/idi_captcha'
|
11
|
-
```
|
12
|
-
|
13
|
-
Then execute:
|
14
|
-
|
15
|
-
```bash
|
16
|
-
bundle install
|
17
|
-
```
|
18
|
-
|
19
|
-
Mount the engine in your `config/routes.rb`:
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
mount IdiCaptcha::Engine => "/idi_captcha"
|
23
|
-
```
|
5
|
+
---
|
24
6
|
|
25
7
|
## ๐ Features
|
26
8
|
|
27
|
-
- Offline
|
9
|
+
- Offline math CAPTCHA (`x + y`)
|
10
|
+
- No image, no external services
|
28
11
|
- Compatible with Rails 6+
|
29
12
|
- Session-based validation
|
30
13
|
- Easy to use with Devise
|
31
|
-
- Image served via internal engine controller
|
32
|
-
|
33
|
-
## ๐งฉ Usage
|
34
|
-
|
35
|
-
### 1. Show CAPTCHA in your form
|
36
|
-
|
37
|
-
For example, in `devise/sessions/new.html.erb`:
|
38
|
-
|
39
|
-
```erb
|
40
|
-
<%= captcha_tag %>
|
41
|
-
|
42
|
-
<div class="field">
|
43
|
-
<%= label_tag :captcha, "Enter CAPTCHA" %>
|
44
|
-
<%= text_field_tag :captcha, nil, required: true, autocomplete: "off" %>
|
45
|
-
</div>
|
46
|
-
```
|
47
|
-
|
48
|
-
### 2. Validate CAPTCHA in your controller
|
49
14
|
|
50
|
-
|
15
|
+
---
|
51
16
|
|
52
|
-
|
53
|
-
class Users::SessionsController < Devise::SessionsController
|
54
|
-
def create
|
55
|
-
unless IdiCaptcha::Captcha.valid?(session, params[:captcha])
|
56
|
-
flash[:alert] = "Invalid CAPTCHA"
|
57
|
-
redirect_to new_user_session_path and return
|
58
|
-
end
|
59
|
-
|
60
|
-
super
|
61
|
-
end
|
62
|
-
end
|
63
|
-
```
|
17
|
+
## ๐ง Installation
|
64
18
|
|
65
|
-
|
19
|
+
Add this line to your application's **Gemfile**:
|
66
20
|
|
67
21
|
```ruby
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
```
|
72
|
-
|
73
|
-
## ๐ Gem Structure
|
74
|
-
|
75
|
-
```text
|
76
|
-
idi_captcha/
|
77
|
-
โโโ lib/
|
78
|
-
โ โโโ idi_captcha.rb
|
79
|
-
โ โโโ idi_captcha/
|
80
|
-
โ โ โโโ captcha.rb
|
81
|
-
โ โ โโโ engine.rb
|
82
|
-
โ โ โโโ helpers/
|
83
|
-
โ โ โโโ view_helper.rb
|
84
|
-
โโโ app/
|
85
|
-
โ โโโ controllers/
|
86
|
-
โ โโโ idi_captcha/
|
87
|
-
โ โโโ captcha_controller.rb
|
88
|
-
โโโ config/
|
89
|
-
โ โโโ routes.rb
|
90
|
-
```
|
91
|
-
|
92
|
-
## โ
Requirements
|
93
|
-
|
94
|
-
- Ruby >= 2.3
|
95
|
-
- Rails >= 6.0
|
96
|
-
- mini_magick >= 4.9, < 5.0
|
97
|
-
|
98
|
-
## ๐งช Testing Locally
|
99
|
-
|
100
|
-
```bash
|
101
|
-
gem build idi_captcha.gemspec
|
102
|
-
bundle install
|
103
|
-
rails server
|
104
|
-
```
|
105
|
-
|
106
|
-
Access `http://localhost:3000/idi_captcha/captcha` to verify the CAPTCHA image loads.
|
107
|
-
|
108
|
-
## ๐ค Author
|
109
|
-
|
110
|
-
**Idrees Ibrahim**
|
111
|
-
๐ง idrees.ibrahim@pitv.gov.pk
|
112
|
-
๐ [RubyGems.org](https://rubygems.org/gems/idi_captcha)
|
113
|
-
|
114
|
-
## ๐ License
|
115
|
-
|
116
|
-
This gem is licensed under a Nonstandard license.
|
22
|
+
gem 'idi_captcha', path: 'relative/path/to/idi_captcha'
|
23
|
+
# Or if published:
|
24
|
+
# gem 'idi_captcha', '~> 0.1.0'
|
data/idi_captcha.gemspec
CHANGED
@@ -10,8 +10,6 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = "A simple image-based CAPTCHA engine for Rails 6+, works offline and supports Devise integration"
|
11
11
|
spec.homepage = "https://rubygems.org/gems/idi_captcha"
|
12
12
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
-
# Add dependency
|
14
|
-
spec.add_dependency 'mini_magick', '>= 4.9', '< 5.0'
|
15
13
|
|
16
14
|
spec.metadata['base_path'] = File.expand_path('..', __FILE__)
|
17
15
|
|
data/lib/idi_captcha/captcha.rb
CHANGED
@@ -1,38 +1,14 @@
|
|
1
1
|
module IdiCaptcha
|
2
2
|
class Captcha
|
3
3
|
def self.generate(session)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
"#{a} + #{b}"
|
9
|
-
else
|
10
|
-
require "mini_magick"
|
11
|
-
|
12
|
-
text = 5.times.map { ('A'..'Z').to_a.sample }.join
|
13
|
-
session[:captcha_text] = text
|
14
|
-
|
15
|
-
# Use MiniMagick::Tool::Convert to generate the image safely
|
16
|
-
MiniMagick::Tool::Convert.new do |c|
|
17
|
-
c.size "150x50"
|
18
|
-
c.gravity "center"
|
19
|
-
c.xc "white"
|
20
|
-
c.fill "black"
|
21
|
-
c.pointsize "32"
|
22
|
-
# Optional: set font if available
|
23
|
-
# c.font "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
24
|
-
c.draw "text 0,0 '#{text}'"
|
25
|
-
c << "png:-" # Output as binary blob
|
26
|
-
end.call
|
27
|
-
end
|
4
|
+
a = rand(1..9)
|
5
|
+
b = rand(1..9)
|
6
|
+
session[:captcha_question] = "#{a} + #{b}"
|
7
|
+
session[:captcha_answer] = a + b
|
28
8
|
end
|
29
9
|
|
30
10
|
def self.valid?(session, input)
|
31
|
-
|
32
|
-
session[:captcha_answer].to_i == input.to_i
|
33
|
-
else
|
34
|
-
session[:captcha_text].to_s.upcase == input.to_s.upcase
|
35
|
-
end
|
11
|
+
session[:captcha_answer].to_i == input.to_i
|
36
12
|
end
|
37
13
|
end
|
38
14
|
end
|
@@ -2,7 +2,11 @@ module IdiCaptcha
|
|
2
2
|
module Helpers
|
3
3
|
module ViewHelper
|
4
4
|
def captcha_tag
|
5
|
-
|
5
|
+
if session[:captcha_question].present?
|
6
|
+
"<label>What is #{session[:captcha_question]}?</label>".html_safe
|
7
|
+
else
|
8
|
+
"<label>CAPTCHA not set</label>".html_safe
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
data/lib/idi_captcha/version.rb
CHANGED
data/lib/idi_captcha.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idi_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- idrees ibrahim
|
@@ -9,27 +9,7 @@ autorequire:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2025-07-28 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: mini_magick
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.9'
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '5.0'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '4.9'
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '5.0'
|
12
|
+
dependencies: []
|
33
13
|
description: A simple image-based CAPTCHA engine for Rails 6+, works offline and supports
|
34
14
|
Devise integration
|
35
15
|
email:
|
@@ -45,10 +25,8 @@ files:
|
|
45
25
|
- Gemfile.lock
|
46
26
|
- README.md
|
47
27
|
- Rakefile
|
48
|
-
- app/controllers/idi_captcha/captcha_controller.rb
|
49
28
|
- bin/console
|
50
29
|
- bin/setup
|
51
|
-
- config/routes.rb
|
52
30
|
- idi_captcha.gemspec
|
53
31
|
- lib/idi_captcha.rb
|
54
32
|
- lib/idi_captcha/captcha.rb
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module IdiCaptcha
|
2
|
-
class CaptchaController < ActionController::Base
|
3
|
-
def show
|
4
|
-
if IdiCaptcha.mode == :math
|
5
|
-
render plain: "Math CAPTCHA enabled. Nothing to show here."
|
6
|
-
else
|
7
|
-
send_data IdiCaptcha::Captcha.generate(session), type: "image/png", disposition: "inline"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/config/routes.rb
DELETED