Class: Ahoy::MessagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/ahoy/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#clickObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/ahoy/messages_controller.rb', line 13

def click
  legacy = params[:id]
  if legacy
    token = params[:id].to_s
    campaign = nil
    url = params[:url].to_s
    signature = params[:signature].to_s
  else
    token = params[:t].to_s
    campaign = params[:c].to_s
    url = params[:u].to_s
    signature = params[:s].to_s
  end

  redirect_options = {}
  redirect_options[:allow_other_host] = true if ActionPack::VERSION::MAJOR >= 7

  if AhoyEmail::Utils.signature_verified?(legacy: legacy, token: token, campaign: campaign, url: url, signature: signature)
    data = {}
    data[:campaign] = campaign if campaign
    data[:token] = token
    data[:url] = url
    data[:controller] = self
    AhoyEmail::Utils.publish(:click, data)

    redirect_to url, **redirect_options
  else
    if AhoyEmail.invalid_redirect_url
      redirect_to AhoyEmail.invalid_redirect_url, **redirect_options
    else
      render plain: "Link expired", status: :not_found
    end
  end
end

#openObject

legacy



9
10
11
# File 'app/controllers/ahoy/messages_controller.rb', line 9

def open
  send_data Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="), type: "image/gif", disposition: "inline"
end