2025-01-13 21:37:02 +01:00
|
|
|
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
2024-12-01 18:43:28 +00:00
|
|
|
|
2024-12-28 18:37:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-12-01 19:42:25 +01:00
|
|
|
class LibreCaptcha
|
2024-12-28 18:19:58 +01:00
|
|
|
def id
|
|
|
|
HTTParty.post('http://libre-captcha:8888/v2/captcha',
|
|
|
|
body: {
|
|
|
|
input_type: 'text',
|
|
|
|
level: :hard,
|
|
|
|
media: 'image/png',
|
|
|
|
size: '350x100'
|
|
|
|
}.to_json).then { |raw| JSON.parse(raw)['id'] }
|
2024-12-01 19:42:25 +01:00
|
|
|
end
|
2024-12-01 19:56:49 +01:00
|
|
|
|
|
|
|
def valid?(id:, answer:)
|
2024-12-28 18:19:58 +01:00
|
|
|
HTTParty.post('http://libre-captcha:8888/v2/answer',
|
|
|
|
body: { id:, answer: }.to_json).then { |raw| JSON.parse(raw)['result'] == 'True' }
|
2024-12-01 19:56:49 +01:00
|
|
|
end
|
2024-12-28 18:19:58 +01:00
|
|
|
end
|