idi_captcha_generator 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/idi_captcha_generator-0.1.0.gem +0 -0
- data/lib/idi_captcha_generator/version.rb +1 -1
- data/lib/idi_captcha_generator.rb +4 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f97ae83dadff3f8cecdeaaf0787765fbf8d6c384197e46409fe40ca9ce05522
|
4
|
+
data.tar.gz: 32116ed5faa9ff35dec8e780c16da28945fbd03adb227a70bfef4aba39affc93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e29d97b07a02b583249b78eca40d8eac2c38533bf57c8bc443d35eb27b3e253c205da5848a5e634d64a01c99321f1d698c57355c91b678c8ea0b8b0123ee1c6
|
7
|
+
data.tar.gz: 2c9025f7984adac2fb8520320f935202633a7c960194cb35826b89532febaf1fe2df1a1b1ff72196d45141d297151325e0f51675ec751eb0d1e0887552e2b904
|
Binary file
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# lib/
|
1
|
+
# lib/idi_captcha_generator.rb
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require_relative "idi_captcha_generator/version"
|
@@ -6,13 +6,11 @@ require 'rmagick' # For image manipulation
|
|
6
6
|
|
7
7
|
module CaptchaGenerator
|
8
8
|
def self.generate_captcha
|
9
|
-
# Randomly generate a simple math question
|
10
9
|
num1 = rand(1..10)
|
11
10
|
num2 = rand(1..10)
|
12
11
|
answer = num1 + num2
|
13
12
|
question = "#{num1} + #{num2} = ?"
|
14
13
|
|
15
|
-
# Create an image with RMagick
|
16
14
|
image = Magick::Image.new(200, 100) {
|
17
15
|
self.background_color = 'white'
|
18
16
|
}
|
@@ -29,7 +27,9 @@ module CaptchaGenerator
|
|
29
27
|
image_path = Rails.root.join('tmp', "captcha_#{Time.now.to_i}.png")
|
30
28
|
image.write(image_path)
|
31
29
|
|
30
|
+
# Clean up temporary files after a certain period
|
31
|
+
File.delete(image_path) if File.exist?(image_path) && Time.now - File.mtime(image_path) > 60 # 1 minute expiry
|
32
|
+
|
32
33
|
{ question: question, answer: answer, image_path: image_path }
|
33
34
|
end
|
34
|
-
class Error < StandardError; end
|
35
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idi_captcha_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Idrees Ibrahim
|
@@ -21,6 +21,7 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
+
- idi_captcha_generator-0.1.0.gem
|
24
25
|
- idi_captcha_generator.gemspec
|
25
26
|
- lib/idi_captcha_generator.rb
|
26
27
|
- lib/idi_captcha_generator/version.rb
|