Module: Bp3::Core::Cookies
Constant Summary collapse
- VISITOR_COOKIE_NAME_PREFIX =
'_bp3_visitor'
- DO_NOT_TRACK_VALUE =
'do_not_track'
Instance Method Summary collapse
-
#check_new_visitor_cookie ⇒ Object
private
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
#check_old_visitor_cookie ⇒ Object
private
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- #check_visitor_cookie ⇒ Object private
- #cookie_site_id ⇒ Object private
- #cookie_tenant_id ⇒ Object private
- #create_visitor ⇒ Object private
- #do_not_track ⇒ Object private
- #new_visitor_cookie_name ⇒ Object private
- #set_do_not_track ⇒ Object private
- #start_tracking ⇒ Object private
- #switch_old_to_new ⇒ Object private
-
#visitor_cookie_name ⇒ Object
private
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
Instance Method Details
#check_new_visitor_cookie ⇒ Object (private)
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bp3/core/cookies.rb', line 91 def = .signed[] return if .blank? && do_not_track identification = sites_site_id = grsc.current_site_id tenant_id = grsc.current_tenant_id visitor = Users::Visitor.find_by(sites_site_id:, tenant_id:, identification:) if visitor.nil? visitor = create_visitor = "check_visitor_cookie: create_visitor #{visitor.id} and create #{} cookie" Rails.logger.debug .signed[] = { value: visitor.identification, expires: 365.days.from_now } end @current_visitor = grsc.current_visitor = visitor Rails.logger.debug do "check_visitor_cookie: cookie[#{}]=#{.signed[]}" end end |
#check_old_visitor_cookie ⇒ Object (private)
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bp3/core/cookies.rb', line 62 def = .signed[] return if .blank? && do_not_track sites_site_id, tenant_id, identification = &.split('/') if sites_site_id && sites_site_id != grsc.current_site.id Rails.logger.warn { "check_visitor_cookie: site mismatch! (#{sites_site_id} and #{grsc.current_site.id}" } end if tenant_id && tenant_id != grsc.current_tenant.id Rails.logger.warn { "check_visitor_cookie: tenant mismatch! (#{tenant_id} and #{grsc.current_tenant.id}" } end visitor = Users::Visitor.find_by(sites_site_id:, tenant_id:, identification:) if visitor.nil? visitor = create_visitor = "check_visitor_cookie: create_visitor #{visitor.id} and create #{} cookie" Rails.logger.debug .signed[] = { value: visitor.scoped_identification, expires: 365.days.from_now } end @current_visitor = grsc.current_visitor = visitor Rails.logger.debug do "check_visitor_cookie: cookie[#{}]=#{.signed[]}" end end |
#check_visitor_cookie ⇒ Object (private)
41 42 43 44 |
# File 'lib/bp3/core/cookies.rb', line 41 def switch_old_to_new end |
#cookie_site_id ⇒ Object (private)
130 131 132 |
# File 'lib/bp3/core/cookies.rb', line 130 def grsc.current_site.id[0..7] end |
#cookie_tenant_id ⇒ Object (private)
134 135 136 |
# File 'lib/bp3/core/cookies.rb', line 134 def grsc.current_tenant.id[0..7] end |
#create_visitor ⇒ Object (private)
123 124 125 126 127 128 |
# File 'lib/bp3/core/cookies.rb', line 123 def create_visitor Users::Visitor.create!(sites_site: grsc.current_site, tenant: grsc.current_tenant, workspaces_workspace: grsc.current_workspace, identification: SecureRandom.uuid) end |
#do_not_track ⇒ Object (private)
19 20 21 22 23 24 25 26 |
# File 'lib/bp3/core/cookies.rb', line 19 def do_not_track return @do_not_track unless @do_not_track.nil? # could be set to true or false already = [] @do_not_track = == DO_NOT_TRACK_VALUE reset_session if @do_not_track @do_not_track end |
#new_visitor_cookie_name ⇒ Object (private)
119 120 121 |
# File 'lib/bp3/core/cookies.rb', line 119 def VISITOR_COOKIE_NAME_PREFIX end |
#set_do_not_track ⇒ Object (private)
28 29 30 31 |
# File 'lib/bp3/core/cookies.rb', line 28 def set_do_not_track # this replaces the signed temporary cookie with an unsigned, permanent cookie .permanent[] = DO_NOT_TRACK_VALUE end |
#start_tracking ⇒ Object (private)
33 34 35 36 37 38 39 |
# File 'lib/bp3/core/cookies.rb', line 33 def start_tracking return unless do_not_track .delete() @do_not_track = false end |
#switch_old_to_new ⇒ Object (private)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bp3/core/cookies.rb', line 46 def switch_old_to_new = .signed[] return if .blank? _sites_site_id, _tenant_id, identification = &.split('/') = "check_visitor_cookie: switching to new visitor_cookie for #{identification}" Rails.logger.debug .delete() .signed[] = { value: identification, expires: 365.days.from_now } end |
#visitor_cookie_name ⇒ Object (private)
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
115 116 117 |
# File 'lib/bp3/core/cookies.rb', line 115 def @visitor_cookie_name ||= "#{VISITOR_COOKIE_NAME_PREFIX}_#{}_#{}" end |