lib/evercookie/controller.rb in evercookie-0.0.6 vs lib/evercookie/controller.rb in evercookie-0.1.0

- old
+ new

@@ -42,10 +42,12 @@ end # controller class defines evercookie actions class EvercookieController < ::ActionController::Base + before_filter :basic_auth, only: [ :ec_auth ] + # Renders javascript with evercookie set script def set @data = session[Evercookie.hash_name_for_set] || {key: '', value: ''} end @@ -85,10 +87,12 @@ 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 # Renders page with cache header for evercookie js script @@ -96,21 +100,35 @@ 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 + # Renders evercookie value for basic authentication if it was set + def ec_auth + render text: @username + end + private + def basic_auth + authenticate_with_http_basic do |username, password| + @username = username + true + end + end + def get_blob_png value = cookies[Evercookie.cookie_png] - + puts "png value (#{Evercookie.cookie_png}): #{value}" require 'chunky_png' image = ChunkyPNG::Image.new(200, 1, ChunkyPNG::Color::BLACK) (0..value.length).step(3) do |index| image[(index / 3).round, 0] = get_pixel_by_index(value, index)