1module Archived |
|
2 class SignaturesController < ApplicationController |
|
3 before_action :retrieve_signature |
|
4 before_action :verify_unsubscribe_token |
|
5 before_action :do_not_cache |
|
|
7 def unsubscribe |
8 @signature.unsubscribe!(token_param) |
|
10 respond_to do |format| |
|
11 format.html
|
|
12 end |
|
13 end |
|
15 private
|
|
|
17 def signature_id |
18 @signature_id ||= Integer(params[:id]) |
|
19 end |
|
|
21 def token_param |
22 @token_param ||= params[:token].to_s.encode('utf-8', invalid: :replace) |
|
23 end |
|
|
25 def verify_unsubscribe_token |
26 unless @signature.unsubscribe_token == token_param |
|
27 raise ActiveRecord::RecordNotFound, "Unable to find Signature with unsubscribe token: #{token_param.inspect}" |
|
28 end |
|
29 end |
|
|
31 def retrieve_signature |
32 @signature = Archived::Signature.find(params[:id]) |
|
33 @petition = @signature.petition |
|
35 if @signature.invalidated? || @signature.fraudulent? |
|
36 raise ActiveRecord::RecordNotFound, "Unable to find Signature with id: #{signature_id}" |
|
37 end |
|
38 end |
|
39 end |
|
40end |