Creating user session only when uploading a screenshot
This makes responses usually cacheable.
This commit is contained in:
parent
773548afc3
commit
df94be866e
2 changed files with 16 additions and 5 deletions
|
|
@ -3,15 +3,15 @@ class ApplicationController < ActionController::Base
|
|||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
before_filter :create_user_token
|
||||
# before_filter :create_user_token
|
||||
|
||||
# Do not mention passwords in the log file
|
||||
# filter_parameter_logging :password
|
||||
|
||||
# Assign the visitor a unique hash so that we can track their uploads
|
||||
# and show them even before moderation.
|
||||
def create_user_token
|
||||
session[:token] ||= SecureRandom.hex
|
||||
session[:ip] ||= request.remote_ip
|
||||
end
|
||||
# def create_user_token
|
||||
# session[:token] ||= SecureRandom.hex
|
||||
# session[:ip] ||= request.remote_ip
|
||||
# end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ class PackagesController < ApplicationController
|
|||
# POST target of the screenshots upload form.
|
||||
# Checks upload images and creates a new Screenshot record for it.
|
||||
def upload_image
|
||||
# Remember the user by the cookie session
|
||||
create_user_token
|
||||
|
||||
@package = Package.find_by(name: params[:name])
|
||||
|
||||
successful_upload_count = 0
|
||||
|
|
@ -220,4 +223,12 @@ class PackagesController < ApplicationController
|
|||
# - Is the user an admin (=logged in)?
|
||||
@screenshot.uploaderhash == session[:token] or user_signed_in?
|
||||
end
|
||||
|
||||
# Store a random identifier and the client's IP address in the session
|
||||
# for later identification.
|
||||
def create_user_token
|
||||
session[:token] ||= SecureRandom.hex
|
||||
session[:ip] ||= request.remote_ip
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue