Class: CaptchaController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Knitkit::Extensions::Railties::ActionController::CaptchaHelper
Defined in:
app/controllers/captcha_controller.rb

Instance Method Summary collapse

Methods included from Knitkit::Extensions::Railties::ActionController::CaptchaHelper

#captcha_valid?

Instance Method Details

#audioObject



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

#imageObject



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_captchaObject



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

#startObject



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

#validateObject



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