Permalink
Browse files

Merge pull request #22 from allourideas/widget-cookie-errors

Widget cookie errors
  • Loading branch information...
lukebaker committed Aug 26, 2013
2 parents ade0683 + 0fb438c commit 47a3211ee34be75a0aaea3ba851c32ebc22d1078
View
@@ -35,6 +35,7 @@ gem "haml", "~> 3.1.7"
gem "compass-rails", "~> 1.0.3"
gem "bootstrap-sass", "~> 2.1.1.0"
gem "mysql2", "0.2.18"
+gem "test-unit", "1.2.3"
group :development do
gem "engineyard"
@@ -45,7 +46,6 @@ group :production, :staging do
end
group :test, :cucumber do
- gem "test-unit", "1.2.3"
gem 'cucumber', '1.1.0'
gem 'cucumber-rails2', '~> 0.3.2'
gem "pickle", "~> 0.4.7"
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
helper :all
protect_from_forgery
- before_filter :initialize_session, :set_session_timestamp, :record_action, :view_filter, :set_pairwise_credentials, :set_locale, :set_p3p_header, :widget_has_redirected
+ before_filter :initialize_session, :set_session_timestamp, :record_action, :view_filter, :set_pairwise_credentials, :set_locale, :set_p3p_header
# preprocess photocracy_view_path on boot because
# doing pathset generation during a request is very costly.
@@ -13,19 +13,6 @@ class ApplicationController < ActionController::Base
@@photocracy_view_path = ActionView::Base.process_view_paths(File.join(Rails.root, "app", "views", "photocracy"))
@@widget_view_path = ActionView::Base.process_view_paths(File.join(Rails.root, "app", "views", "widget"))
- # for the widget third-party cookie busting attempts
- # check redis to see if we've redirected this client
- # if we have, then we won't attempt to do so again
- def widget_has_redirected
- @widget_has_redirected = false
- return unless @widget
- r = Redis.new(:host => REDIS_CONFIG['hostname'])
- redis_key = "redirect_" + Digest::MD5.hexdigest("#{request.remote_ip} #{request.env["HTTP_USER_AGENT"]} #{request.referer}")
- if r.get(redis_key) == "1"
- @widget_has_redirected = true
- end
- end
-
def view_filter
if request.url.include?('photocracy') || request.url.include?('fotocracy') || @photocracy || (RAILS_ENV == 'test' && $PHOTOCRACY)
@photocracy = true
@@ -100,6 +87,7 @@ def record_action
:user_agent => request.env["HTTP_USER_AGENT"],
:white_label_request => white_label_request?,
:visitor_id => visitor.id)
+ @user_session = user_session
sql = ActiveRecord::Base.send(:sanitize_sql_array, ["INSERT INTO `clicks` (`url`, `controller`, `action`, `user_id`, `referrer`, `session_info_id`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", request.url, controller_name, action_name, current_user.try(:id), request.referrer, user_session.try(:id), Time.now.utc, Time.now.utc])
ActiveRecord::Base.connection.execute(sql)
@@ -4,15 +4,7 @@ class HomeController < ApplicationController
before_filter :authenticate, :only => [:admin]
before_filter :admin_only, :only => [:no_google_tracking]
- def redirect
- # keep track of this client's redirect for 20 seconds, so we don't get in redirect loop
- r = Redis.new(:host => REDIS_CONFIG['hostname'])
- redis_key = "redirect_" + Digest::MD5.hexdigest("#{request.remote_ip} #{request.env["HTTP_USER_AGENT"]} #{params[:redirect_to]}")
- r.set(redis_key, 1)
- r.expire(redis_key, 20)
- location = params[:redirect_to] || '/'
- redirect_to(location)
- end
+ skip_before_filter :initialize_session, :set_session_timestamp, :record_action, :view_filter, :set_pairwise_credentials, :set_locale, :set_p3p_header, :only => [:cookies_blocked]
def index
@example_earl = 'planyc_example'
@@ -28,6 +20,12 @@ def index
def no_google_tracking
end
+ def cookies_blocked
+ BlockedCookie.create(:ip_addr => request.remote_ip, :question_id => params[:question_id], :referrer => params[:referrer], :source => request.referrer, :user_agent => request.env["HTTP_USER_AGENT"], :session_id => params[:session_id])
+ # send 1x1 gif in response
+ send_data(Base64.decode64('R0lGODlhAQABAAAAADs='), :type => "image/gif", :disposition => "inline")
+ end
+
def example
redirect_to("/planyc_example") and return
end
@@ -58,6 +56,8 @@ def admin
@available_charts['user_submitted_ideas'] = { :title => "Number of all submitted ideas over time"}
@available_charts['user_sessions'] = { :title => "Number of all user sessions per day"}
@available_charts['unique_users'] = { :title => "Number of all unique users per day"}
+
+ @blocked_cookies = BlockedCookie.today.group_by(&:question_id)
else
@earls = current_user.earls.sort_by {|x| [(!x.active).to_s, x.name]}
@questions = Question.find(:all, :params => {
@@ -0,0 +1,3 @@
+class BlockedCookie < ActiveRecord::Base
+ named_scope :today, :conditions => ["created_at >= ?", Time.now.beginning_of_day]
+end
@@ -9,6 +9,15 @@
- bg_color = ab_test("bg_color_aa_#{@earl.name}", ['#F2F2F2', '#F2F2F1'], :conversion => 'voted')
.tab-content.question-vote.row-fluid{:style => "background-color: #{bg_color}"}
+ #cookies-failed{:style => "display: none;"}
+ %div
+ %h2 Cookies Blocked
+ %p
+ = link_to("Cookies are required", 'http://blog.allourideas.org/post/54515392435/cookies')
+ for voting, and it looks like cookies may be disabled in your browser.
+ In order to vote, you must allow cookies from allourideas.org. For more information, please read
+ this blog post about our
+ = link_to('cookie policy.', 'http://blog.allourideas.org/post/54515392435/cookies')
-if !session[:has_voted] && session[:welcome_msg]
.row-fluid
.span10.offset1.welcome-message
@@ -92,6 +101,24 @@
-content_for :view_javascript do
+ :plain
+ // Test if we can set and read cookies.
+ // If we can't, then the browser probably has 3rd party cookies disabled
+ // unless the user has first navigated to the domain serving the iframe source.
+ var cookieValue = "cookieTest" + new Date().getTime();
+ document.cookie = "cookieTest="+cookieValue;
+ if (document.cookie.indexOf("cookieTest="+cookieValue) === -1) {
+ var cookies_failed = document.getElementById('cookies-failed');
+ if (cookies_failed) {
+ cookies_failed.style.display = 'block';
+ var img = new Image();
+ img.src = '/cookies_blocked.gif?question_id=#{@earl.question_id}&session_id=#{@user_session.session_id}&referrer=' + encodeURIComponent(document.referrer);
+ }
+ }
+ else {
+ // cleanup test cookie
+ document.cookie = 'cookieTest=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
+ }
$('.rounded').corner('5px');
-unless session[:has_voted]
:plain
@@ -54,6 +54,18 @@
%p
= link_to("See all", admin_path(:all => 'true'), :class => 'btn btn-inverse')
-if current_user.admin?
+ -if @blocked_cookies && @blocked_cookies.count > 0
+ %h4 Today's Blocked Cookies
+ %table.table
+ %thead
+ %tr
+ %th Survey
+ %th Count
+ %tbody
+ - @blocked_cookies.each do |question_id, bc|
+ %tr
+ %td= "/#{Earl.find_by_question_id(question_id).name}"
+ %td= bc.count
%table.table
%thead
%tr
@@ -1,6 +1,17 @@
-@item_data, @item_ids = [], []
-.scrollbar_container
+#cookies-failed.scrollbar_container{:style => "display: none;"}
+ .aboutpage
+ %h2 Cookies Blocked
+ %p
+ = link_to("Cookies are required", 'http://blog.allourideas.org/post/54515392435/cookies', :target => '_blank')
+ for voting, and it looks like third-party cookies may be disabled in your browser.
+ In order to vote, you may
+ = link_to("vote on the main site", @cast_votes_url, :target => '_blank')
+ or allow
+ = link_to("third-party cookies", 'http://en.wikipedia.org/wiki/Third-party_cookie#Privacy_and_third-party_cookies', :target => '_blank')
+ in your browser.
+#voting-container.scrollbar_container
.question_container
%table.question.center.no_padding
%tr
@@ -1,115 +1,113 @@
-%html{:xmlns => "http://www.w3.org/1999/xhtml", :'xml:lang' => "en", :lang => "en"}
- %head
- %meta{:'http-equiv' => "content-type", :content => "text/html;charset=UTF-8"}
- %meta{:NAME =>"ROBOTS", :CONTENT => "NOINDEX, NOFOLLOW"}
- :css
- .body {
- color: #{@text_on_white}; }
+- content_for :head do
+ %meta{:'http-equiv' => "content-type", :content => "text/html;charset=UTF-8"}
+ %meta{:NAME =>"ROBOTS", :CONTENT => "NOINDEX, NOFOLLOW"}
+ :css
+ .body {
+ color: #{@text_on_white}; }
- .idea_result {
- color: #{@text_on_white}; }
+ .idea_result {
+ color: #{@text_on_white}; }
- h1, h2, h3, h4, h5, h6, .large-text {
- color: #{@lighter_text_on_white}; }
+ h1, h2, h3, h4, h5, h6, .large-text {
+ color: #{@lighter_text_on_white}; }
- a {
- color: #{@flag_text_color}; }
+ a {
+ color: #{@flag_text_color}; }
- .bar-chart > div {
- background-color: #{@lighter_text_on_white}; }
+ .bar-chart > div {
+ background-color: #{@lighter_text_on_white}; }
- .bottom_status {
- color: #{@text_on_color};
- background-color: #{@vote_button_color};
- border-color: #{@vote_button_color}; }
+ .bottom_status {
+ color: #{@text_on_color};
+ background-color: #{@vote_button_color};
+ border-color: #{@vote_button_color}; }
- .question {
- color: #{@question_text_color}; }
+ .question {
+ color: #{@question_text_color}; }
- table .row0 {
- color: #{@text_on_color};
- background-color: #{@vote_button_color}; }
+ table .row0 {
+ color: #{@text_on_color};
+ background-color: #{@vote_button_color}; }
- .scrollbar_container {
- border-color: #{@vote_button_color}; }
-
- .tabs {
- border-color: #{@vote_button_color}; }
- .tabs .current_tab {
- background-color: #{@vote_button_color}; }
- .tabs .current_tab:hover {
- background-color: #{@vote_button_color};
- border-color: #{@vote_button_color}; }
- .tabs li {
- border-top-color: #{@vote_button_color};
- border-left-color: #{@vote_button_color};
- border-right-color: #{@vote_button_color}; }
- .tabs li a {
- color: #{@vote_button_color}; }
- .tabs li:hover {
- background-color: #{@tab_hover_color};
- border-color: #{@tab_hover_color}; }
-
- .votebox table td.vote_cell {
- color: #{@text_on_color};
- background: #{@vote_button_color}; }
- .votebox table td.vote_cell:hover {
- background: #{@vote_button_hover_color}; }
- .votebox table td.vote_cell a {
- color: #{@text_on_color}; }
- .votebox table td.vote_cell a:hover {
- color: #{@text_on_color}; }
-
- .new_idea_submit, .flag_submit_button, .cd_submit_button {
- color: #{@text_on_color};
- background: #{@submit_button_color}; }
- .new_idea_submit:hover, .flag_submit_button:hover, .cd_submit_button:hover {
- background-color: #{@submit_button_hover_color}; }
-
- #cant_decide_btn {
- color: #{@text_on_color};
- background: #{@cant_decide_button_color}; }
- #cant_decide_btn:hover {
- background-color: #{@cant_decide_button_hover_color}; }
- .cd_option .cd_box a {
- color: #{@text_on_color};
- background: #{@cant_decide_button_color}; }
- .cd_option .cd_box a:hover {
- background-color: #{@cant_decide_button_hover_color}; }
-
- .add_idea .add_idea_button {
- color: #{@text_on_color};
- background: #{@add_idea_button_color}; }
- .add_idea .add_idea_button a {
+ .scrollbar_container {
+ border-color: #{@vote_button_color}; }
+
+ .tabs {
+ border-color: #{@vote_button_color}; }
+ .tabs .current_tab {
+ background-color: #{@vote_button_color}; }
+ .tabs .current_tab:hover {
+ background-color: #{@vote_button_color};
+ border-color: #{@vote_button_color}; }
+ .tabs li {
+ border-top-color: #{@vote_button_color};
+ border-left-color: #{@vote_button_color};
+ border-right-color: #{@vote_button_color}; }
+ .tabs li a {
+ color: #{@vote_button_color}; }
+ .tabs li:hover {
+ background-color: #{@tab_hover_color};
+ border-color: #{@tab_hover_color}; }
+
+ .votebox table td.vote_cell {
+ color: #{@text_on_color};
+ background: #{@vote_button_color}; }
+ .votebox table td.vote_cell:hover {
+ background: #{@vote_button_hover_color}; }
+ .votebox table td.vote_cell a {
+ color: #{@text_on_color}; }
+ .votebox table td.vote_cell a:hover {
color: #{@text_on_color}; }
- .add_idea .add_idea_button:hover {
- background: #{@add_idea_button_hover_color}; }
- .link_style a {
+ .new_idea_submit, .flag_submit_button, .cd_submit_button {
+ color: #{@text_on_color};
+ background: #{@submit_button_color}; }
+ .new_idea_submit:hover, .flag_submit_button:hover, .cd_submit_button:hover {
+ background-color: #{@submit_button_hover_color}; }
+
+ #cant_decide_btn {
+ color: #{@text_on_color};
+ background: #{@cant_decide_button_color}; }
+ #cant_decide_btn:hover {
+ background-color: #{@cant_decide_button_hover_color}; }
+ .cd_option .cd_box a {
+ color: #{@text_on_color};
+ background: #{@cant_decide_button_color}; }
+ .cd_option .cd_box a:hover {
+ background-color: #{@cant_decide_button_hover_color}; }
+
+ .add_idea .add_idea_button {
+ color: #{@text_on_color};
+ background: #{@add_idea_button_color}; }
+ .add_idea .add_idea_button a {
color: #{@text_on_color}; }
+ .add_idea .add_idea_button:hover {
+ background: #{@add_idea_button_hover_color}; }
+
+ .link_style a {
+ color: #{@text_on_color}; }
-%body
- -@the_id = params[:question_id].nil? ? params[:id] : params[:question_id]
+-@the_id = params[:question_id].nil? ? params[:id] : params[:question_id]
- = render :partial => 'shared/header_vote', :locals => {:question => @question}
+= render :partial => 'shared/header_vote', :locals => {:question => @question}
- #cast_votes.current
- = render 'cast_votes.html.haml'
+#cast_votes.current
+ = render 'cast_votes.html.haml'
- #results{:style => 'display:none'}
- .scrollbar_container#render_spot
- %center
- %br
- = 'Loading results...'
- .bottom_status.link_style
- %span.bottom_padding
- /* Use a table here to fix a small issue with a non-linking space after the first link */
- %table.fleft
- %td{:style => 'padding-left: 5px;'}= link_to(t('nav.view_more_results_widget'),"http://www.allourideas.org" + @results_url, :target => '_blank', :id => 'view_more_results')
- %td= link_to(image_tag('widget/lpadded_outgoing_link.png'), "http://www.allourideas.org" + @results_url, :target => '_blank')
- %span
- %a.bottom_padding.fright.return_voting{:href => '#page1'}= t('nav.return_voting_widget');
+#results{:style => 'display:none'}
+ .scrollbar_container#render_spot
+ %center
+ %br
+ = 'Loading results...'
+ .bottom_status.link_style
+ %span.bottom_padding
+ /* Use a table here to fix a small issue with a non-linking space after the first link */
+ %table.fleft
+ %td{:style => 'padding-left: 5px;'}= link_to(t('nav.view_more_results_widget'), @results_url, :target => '_blank', :id => 'view_more_results')
+ %td= link_to(image_tag('widget/lpadded_outgoing_link.png'), @results_url, :target => '_blank')
+ %span
+ %a.bottom_padding.fright.return_voting{:href => '#page1'}= t('nav.return_voting_widget');
- #about{:style => 'display:none'}
- = render 'questions/about.html.haml'
+#about{:style => 'display:none'}
+ = render 'questions/about.html.haml'
Oops, something went wrong.

0 comments on commit 47a3211

Please sign in to comment.