Sha256: 5ccea607b03d002bc009753212300b4b8357374984db07516b561cfce462e2a6

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

module Extr
 class RouterController < ActionController::Base

  protect_from_forgery

  respond_to :html, :json

  def direct
   body = transactions.map(&:response)

   if request.form_data? and extjs_form_with_upload
    render :inline => "<html><body><textarea>#{body.to_json}</textarea></body></html>", :content_type => 'text/html'
   else
    render :json => body ||= ""
   end
  end

 private

  def extjs_form_with_upload
   params.select{|k,v| v.class == ActionDispatch::Http::UploadedFile}.any?
  end

  def transactions
   @transactions ||= collect_transactions
  end

  def collect_transactions
   arr = []
   raw_http_params.each do |p|
    if request.form_data?
      t = Transaction.new(request,
                          p[:extAction],
                          p[:extMethod],
                          p[:extTID],
                          p[:data],
                          p[:extUpload]
      )
    else
      t = Transaction.new(request,
                          p[:action],
                          p[:method],
                          p[:tid],
                          p[:data],
                          false
      )
    end
    arr << t if t.valid?
   end
   return arr
  end

  def raw_http_params
   parse request.env["action_dispatch.request.request_parameters"]
  end

  def parse(data)
   return (data["_json"]) ? data["_json"] : [data]
  end

 protected

  def handle_unverified_request
   reset_session
   body = []
   transactions.each do |t|
    body << {
      'type'    => 'exception',
      'tid'     => t.tid,
      'action'  => t.action,
      'method'  => t.method,
      'result'  => "WARNING: Can't verify CSRF token authenticity"
    }
   end
   render :json => body

  end


 end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
extr-1.0.2 app/controllers/extr/router_controller.rb
extr-1.0.1 app/controllers/extr/router_controller.rb
extr-1.0.0 app/controllers/extr/router_controller.rb