rucaptcha/app/controllers/ru_captcha/captcha_controller.rb

23 lines
804 B
Ruby
Raw Normal View History

2015-10-26 06:09:39 +00:00
module RuCaptcha
class CaptchaController < ActionController::Base
def index
2017-03-09 08:42:43 +00:00
return head :ok if request.head?
2015-10-26 06:09:39 +00:00
headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
headers['Pragma'] = 'no-cache'
2022-10-25 04:02:54 +00:00
if params[:t].present? && (!params[:t].is_i? rescue true)
render :body => nil, :status => 404 and return
end
2022-10-13 05:06:24 +00:00
if params[:format] == "wav" and RuCaptcha.espeak?
data = generate_speech_rucaptcha
opts = { disposition: 'inline', type: 'audio/wav' }
2022-10-25 03:48:15 +00:00
elsif params[:format].blank? || params[:format] == "gif"
2022-10-13 05:06:24 +00:00
data = generate_rucaptcha
opts = { disposition: 'inline', type: 'image/gif' }
2022-10-25 03:48:15 +00:00
else
render :body => nil, :status => 404 and return
2022-10-13 05:06:24 +00:00
end
2017-03-22 07:52:21 +00:00
send_data data, opts
2015-10-26 06:09:39 +00:00
end
end
end