jam-cloud/web/app/controllers/application_controller.rb

74 lines
2.3 KiB
Ruby

require 'bugsnag'
class ApplicationController < ActionController::Base
protect_from_forgery
include ApplicationHelper
include SessionsHelper
include ClientHelper
force_ssl port: Rails.application.config.external_port_ssl if Rails.application.config.force_ssl
# inject username/email into bugsnag data
before_bugsnag_notify :add_user_info_to_bugsnag
before_filter do
gon_setup
end
before_filter :set_tracking_cookie
before_filter :track_affiliate_visits
before_filter do
if params[AffiliatePartner::PARAM_REFERRAL].present? && current_user.nil?
if cookies[AffiliatePartner::PARAM_COOKIE].blank?
code = params[AffiliatePartner::PARAM_REFERRAL].downcase
cookies[AffiliatePartner::PARAM_COOKIE] = code if AffiliatePartner.is_code?(code)
end
end
end
def affiliate_code
cookies[AffiliatePartner::PARAM_COOKIE]
end
# http://stackoverflow.com/questions/15807214/where-to-set-a-tracking-permanent-cookie-in-rails
def set_tracking_cookie
cookies.permanent[:user_uuid] = SecureRandom.uuid unless cookies[:user_uuid]
end
def track_affiliate_visits
if params[:affiliate]
visit_cookie = cookies[:affiliate_visitor]
AffiliateReferralVisit.track(affiliate_id: params[:affiliate], visited: visit_cookie, remote_ip: request.remote_ip, visited_url: request.fullpath, referral_url: request.referer, current_user: current_user)
# set a cookie with the ID of the partner, and expires in 24 hours
cookies[:affiliate_visitor] = { :value => params[:affiliate], :expires => Time.now + 3600 * 24} # 1 day from now
end
end
private
def add_user_info_to_bugsnag(notif)
# Add some app-specific data which will be displayed on a custom
# "User Info" tab on each error page on bugsnag.com
unless current_user.nil?
notif.add_tab(:user_info, {
name: current_user.name,
email: current_user.email
})
end
end
end
class ControllerHelp
include Singleton
include ActionView::Helpers::TextHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::SanitizeHelper
extend ActionView::Helpers::SanitizeHelper::ClassMethods
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::AssetTagHelper
end