1class TrackersController < ApplicationController |
|
2 include FormTracking |
|
4 before_action :fetch_petition |
|
5 before_action :verify_petition |
|
6 before_action :verify_form_token |
|
7 before_action :do_not_cache |
|
|
9 def show |
10 cookies.encrypted[form_token] = current_time
|
|
12 respond_to do |format| |
|
13 format.gif
|
|
14 end |
|
15 end |
|
17 private
|
|
|
19 def petition_id |
20 @petition_id ||= Integer(params[:petition_id]) |
|
21 end |
|
|
23 def fetch_petition |
24 @petition = Petition.visible.find(petition_id) |
|
25 end |
|
|
27 def verify_petition |
28 if @petition.closed_for_signing? |
|
29 raise ActionController::BadRequest, "Petition has been closed" |
|
30 end |
|
31 end |
|
|
33 def verify_form_token |
34 unless form_token == params[:id] |
|
35 raise ActionController::BadRequest, "The token in the session doesn't match the url token" |
|
36 end |
|
37 end |
|
38end |