Class: Evercookie::EvercookieController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/evercookie/controller.rb

Overview

controller class defines evercookie actions

Instance Method Summary collapse

Instance Method Details

#ec_authObject

Renders evercookie value for basic authentication if it was set


116
117
118
# File 'lib/evercookie/controller.rb', line 116

def ec_auth
  render text: @username
end

#ec_cacheObject

Renders page with cache header for evercookie js script


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/evercookie/controller.rb', line 99

def ec_cache
  if not cookies[Evercookie.cookie_cache].present?
    render :nothing => true, :status => 304
    return true
  end

  puts "cache value (#{Evercookie.cookie_cache}): #{cookies[Evercookie.cookie_cache]}"

  response.headers["Content-Type"] = "text/html"
  response.headers["Last-Modified"] = "Wed, 30 Jun 2010 21:36:48 GMT"
  response.headers["Expires"] = "Tue, 31 Dec 2030 23:30:45 GMT"
  response.headers["Cache-Control"] = "private, max-age=630720000"

  render text: cookies[Evercookie.cookie_cache]
end

#ec_etagObject

Renders page with etag header for evercookie js script


86
87
88
89
90
91
92
93
94
95
96
# File 'lib/evercookie/controller.rb', line 86

def ec_etag
  if not cookies[Evercookie.cookie_etag].present?
    render :text => request.headers['If-None-Match'] || '', :status => 304
    return true
  end

  puts "cache value (#{Evercookie.cookie_etag}): #{cookies[Evercookie.cookie_etag]}"

  response.headers["Etag"] = cookies[Evercookie.cookie_etag]
  render text: cookies[Evercookie.cookie_etag]
end

#ec_pngObject

Renders png image with encoded evercookie value in it


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/evercookie/controller.rb', line 71

def ec_png
  if not cookies[Evercookie.cookie_png].present?
    render :nothing => true, :status => 304
    return true
  end

  response.headers["Content-Type"] = "image/png"
  response.headers["Last-Modified"] = "Wed, 30 Jun 2010 21:36:48 GMT"
  response.headers["Expires"] = "Tue, 31 Dec 2030 23:30:45 GMT"
  response.headers["Cache-Control"] = "private, max-age=630720000"

  render text: get_blob_png, status: 200, content_type: 'image/png'
end

#getObject

Renders javascript with evercookie get script


55
56
57
# File 'lib/evercookie/controller.rb', line 55

def get
  @data = session[Evercookie.hash_name_for_get] || {key: '', value: ''}
end

#saveObject

Saves current evercookie value to session


60
61
62
63
64
65
66
67
68
# File 'lib/evercookie/controller.rb', line 60

def save
  if data = session[Evercookie.hash_name_for_get]
    if data[:key] && cookies[data[:key]]
      session[Evercookie.hash_name_for_saved] =
          { data[:key] => cookies[data[:key]] }
    end
  end
  render nothing: true
end

#setObject

Renders javascript with evercookie set script


50
51
52
# File 'lib/evercookie/controller.rb', line 50

def set
  @data = session[Evercookie.hash_name_for_set] || {key: '', value: ''}
end