* Initial controller creation * Ahoy custom clicks initial WIP * Add test for success and failure * Adjust some tests * Adjust test * Adjust tests and some code * Update app/views/mailers/digest_mailer/digest_email.html.erb * Remove s/t/u from safe params * Add simple test * Update app/controllers/ahoy/custom_email_clicks_controller.rb Co-authored-by: Mac Siri <mac@forem.com> * Change to just email clicks * Email clicks controller test --------- Co-authored-by: Mac Siri <mac@forem.com>
35 lines
975 B
Ruby
35 lines
975 B
Ruby
module Ahoy
|
|
class EmailClicksController < ApplicationController
|
|
skip_before_action :verify_authenticity_token # Signitures are used to verify requests here
|
|
before_action :verify_signature
|
|
|
|
def create
|
|
data = {
|
|
token: @token,
|
|
campaign: @campaign,
|
|
url: @url,
|
|
controller: self
|
|
}
|
|
AhoyEmail::Utils.publish(:click, data)
|
|
head :ok # Renders a blank response with a 200 OK status
|
|
end
|
|
|
|
private
|
|
|
|
def verify_signature
|
|
@token = ahoy_params[:t].to_s
|
|
@campaign = ahoy_params[:c].to_s
|
|
@url = ahoy_params[:u].to_s
|
|
@signature = ahoy_params[:s].to_s
|
|
expected_signature = AhoyEmail::Utils.signature(token: @token, campaign: @campaign, url: @url)
|
|
|
|
return if ActiveSupport::SecurityUtils.secure_compare(@signature, expected_signature)
|
|
|
|
render plain: "Invalid signature", status: :forbidden
|
|
end
|
|
|
|
def ahoy_params
|
|
params.permit(:t, :c, :u, :s)
|
|
end
|
|
end
|
|
end
|