VRFS-1576 case insensitive codes

This commit is contained in:
Jonathan Kolyer 2014-04-22 02:14:22 +00:00
parent 6ee83f8dcc
commit af63b03d6a
2 changed files with 9 additions and 7 deletions

View File

@ -17,7 +17,7 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
def self.create_with_params(params={})
oo = self.new
oo.partner_name = params[:partner_name].try(:strip)
oo.partner_code = params[:partner_code].try(:strip)
oo.partner_code = params[:partner_code].try(:strip).try(:downcase)
oo.partner_user = User.where(:email => params[:user_email].try(:strip)).limit(1).first
oo.partner_user_id = oo.partner_user.try(:id)
oo.save
@ -28,5 +28,8 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
self.where(:partner_code => code).limit(1).pluck(:id).first if code.present?
end
end
def self.is_code?(code)
self.where(:partner_code => code).limit(1).pluck(:id).present?
end
end

View File

@ -4,15 +4,14 @@ class ApplicationController < ActionController::Base
include ApplicationHelper
include SessionsHelper
# inject username/email into bugsnag data
before_bugsnag_notify :add_user_info_to_bugsnag
before_filter do
if current_user.nil?
if (code = params[AffiliatePartner::PARAM_REFERRAL]).present? &&
cookies[AffiliatePartner::PARAM_COOKIE].blank?
cookies[AffiliatePartner::PARAM_COOKIE] = code
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