Sha256: 56e668bec8e6f4a6e42bc824f4fce0184f4ed2e0ae5076fad2659eacf67615f0

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

module Ahoy
  class MessagesController < ActionController::Base
    before_filter :set_message

    def open
      if @message and !@message.opened_at
        @message.opened_at = Time.now
        @message.save!
      end
      send_data Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="), type: "image/gif", disposition: "inline"
    end

    def click
      if @message and !@message.clicked_at
        @message.clicked_at = Time.now
        @message.save!
      end
      url = params[:url]
      signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"), AhoyEmail.secret_token, url)
      if params[:signature] == signature
        redirect_to url
      else
        redirect_to main_app.root_url
      end
    end

    protected

    def set_message
      @message = Ahoy::Message.where(token: params[:id]).first
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ahoy_email-0.0.2 app/controllers/ahoy/messages_controller.rb