Class: SimpleCaptcha::Middleware

Inherits:
Object
  • Object
show all
Includes:
ImageHelpers, ViewHelper
Defined in:
lib/simple_captcha/middleware.rb

Constant Summary collapse

DEFAULT_SEND_FILE_OPTIONS =
{
  :type         => 'application/octet-stream'.freeze,
  :disposition  => 'attachment'.freeze,
}.freeze

Constants included from ImageHelpers

ImageHelpers::DEFAULT_IMPLODE, ImageHelpers::DISTORTIONS, ImageHelpers::IMPLODES

Instance Method Summary collapse

Methods included from ViewHelper

#show_simple_captcha, #simple_captcha_options

Methods included from ImageHelpers

distortion, image_params, implode

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



12
13
14
15
# File 'lib/simple_captcha/middleware.rb', line 12

def initialize(app, options={})
  @app = app
  self
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simple_captcha/middleware.rb', line 17

def call(env) # :nodoc:
  if env["REQUEST_METHOD"] == "GET" && captcha_path?(env['PATH_INFO'])
    request = Rack::Request.new(env)
    if request.params.present? && request.params['code'].present?
      make_image(env)
    else
      refresh_code(env)
    end
  else
    @app.call(env)
  end
end