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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2378387cc52281bb11dbe6b4544801048b9706b6b4c9ef839a78c655a26feebe
4
- data.tar.gz: af8c5e69aa2cf7d1f9b5b2dc0ea03e357c0a0a25b09a3cc0b32712deed1b30ca
3
+ metadata.gz: 45261bbd789a3d888a5f1ae4991c361a3001705e07d999f0e7ed7b643c71f8df
4
+ data.tar.gz: '059687e5cf34b5182623d0311a76e9db8499adf50513902309cdc322f6c90b48'
5
5
  SHA512:
6
- metadata.gz: d2a84c7d86c83537f3515a51648e88605c5cecdf7ab9b0cd66c18fca300e2e8b2cb85f0a732e2d5bf4992d2f7e4988ad2adf822b3605a0bd216105217254bb5e
7
- data.tar.gz: 0bb88c07c4c2a6f6ee774a9a7823c7e762874cc140d00ba7cdac029b03b3b130d6cb0e060f1dd77610d71a56641a6e3b49599b1f1c49ccd147f1b54e70fe3b81
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
- ## ๐Ÿ”ง Installation
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 image CAPTCHA (no Google reCAPTCHA)
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
- Override Devise's sessions controller:
15
+ ---
51
16
 
52
- ```ruby
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
- Update routes:
19
+ Add this line to your application's **Gemfile**:
66
20
 
67
21
  ```ruby
68
- devise_for :users, controllers: {
69
- sessions: 'users/sessions'
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
 
@@ -1,38 +1,14 @@
1
1
  module IdiCaptcha
2
2
  class Captcha
3
3
  def self.generate(session)
4
- if IdiCaptcha.mode == :math
5
- a = rand(1..9)
6
- b = rand(1..9)
7
- session[:captcha_answer] = a + b
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
- if IdiCaptcha.mode == :math
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
- image_tag("/idi_captcha/captcha?#{Time.now.to_i}", alt: 'CAPTCHA')
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
@@ -1,3 +1,3 @@
1
1
  module IdiCaptcha
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/idi_captcha.rb CHANGED
@@ -4,10 +4,4 @@ require "idi_captcha/captcha"
4
4
  require "idi_captcha/helpers/view_helper"
5
5
 
6
6
  module IdiCaptcha
7
- mattr_accessor :mode
8
- self.mode = :image # or :math
9
-
10
- def self.setup
11
- yield self
12
- end
13
7
  end
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: 1.1.0
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
@@ -1,3 +0,0 @@
1
- IdiCaptcha::Engine.routes.draw do
2
- get 'captcha', to: 'captcha#show'
3
- end