Class: CaptchaController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- CaptchaController
- Defined in:
- app/controllers/captcha_controller.rb
Instance Method Summary collapse
Methods included from Knitkit::Extensions::Railties::ActionController::CaptchaHelper
Instance Method Details
#audio ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/captcha_controller.rb', line 22 def audio captcha = VisualCaptcha::Captcha.new @session type = params[:type] type = 'mp3' if type != 'ogg' if (body = captcha.stream_audio @headers, type) send_data body, type: type, disposition: 'inline' else raise ActionController::RoutingError.new('Not Found') end end |
#image ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/captcha_controller.rb', line 35 def image captcha = VisualCaptcha::Captcha.new @session if (body = captcha.stream_image @headers, params[:index], params[:retina]) send_data body, type: 'image/png', disposition: 'inline' else raise ActionController::RoutingError.new('Not Found') end end |
#setup_visual_captcha ⇒ Object
7 8 9 10 11 12 |
# File 'app/controllers/captcha_controller.rb', line 7 def setup_visual_captcha @session = VisualCaptcha::Session.new session @headers = { 'Access-Control-Allow-Origin' => '*' } end |
#start ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/controllers/captcha_controller.rb', line 14 def start captcha = VisualCaptcha::Captcha.new @session captcha.generate params[:how_many] render json: captcha.frontend_data end |
#validate ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/controllers/captcha_controller.rb', line 45 def validate if captcha_valid? render json: {success: true} else render json: {success: false} end end |