Class: Wco::UnsubscribesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wco/unsubscribes_controller.rb

Overview

In order to have unsubscribes_url , unsubscribes must be in wco .

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #tinymce

Methods included from ApplicationHelper

#my_truthy?, #obfuscate, #pexels_search_path, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/wco/unsubscribes_controller.rb', line 8

def create
  authorize! :open_permission, Wco
  @lead = Wco::Lead.find params[:lead_id]

  if( !params[:token] ||
      @lead.unsubscribe_token != params[:token] )
    render code: 400, message: "We're sorry, but something went wrong. Please try again later."
    return
  end

  @unsubscribe = WcoEmail::Unsubscribe.find_or_create_by({
    lead_id:     params[:lead_id],
    template_id: params[:template_id],
    campaign_id: params[:campaign_id],
  })
  flag = @unsubscribe.update_attributes({
    unsubscribed_at: Time.now,
  })
  if flag
    flash_notice "You have been unsubscribed."
  else
    flash_alert "We're sorry, but something went wrong. Please try again later."
  end

  render layout: false
end

#do_unsubscribeObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/wco/unsubscribes_controller.rb', line 35

def do_unsubscribe
  authorize! :open_permission, Wco
  lead = Wco::Lead.find_by email: params[:email]
  if params[:token] == lead.unsubscribe_token
    lead.update({ unsubscribed_at: Time.now })
    flash[:notice] = 'You have been unsubscribed!'
    render 'success', layout: false
  else
    flash[:error] = 'security token mismatch.'
    render 'error', layout: false
  end
end

#indexObject



48
49
50
51
52
53
# File 'app/controllers/wco/unsubscribes_controller.rb', line 48

def index
  authorize! :index, WcoEmail::Unsubscribe
  @unsubscribes = WcoEmail::Unsubscribe.all

  render '_table'
end

#newObject



55
56
57
58
# File 'app/controllers/wco/unsubscribes_controller.rb', line 55

def new
  authorize! :open_permission, Wco
  render layout: false
end