Skip to content

Commit

Permalink
Merge pull request #47 from jlcapps/issue_46_remove_protect_from_forg…
Browse files Browse the repository at this point in the history
…ery_call

Remove protect_from_forgery call
  • Loading branch information
pelargir authored May 21, 2024
2 parents 6c6849a + 82156ad commit 0fa1d9f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/auto_session_timeout.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module AutoSessionTimeout

def self.included(controller)
controller.extend ClassMethods
end

module ClassMethods
def auto_session_timeout(seconds=nil)
protect_from_forgery except: [:active, :timeout]
prepend_before_action do |c|
if session_expired?(c) && !signing_in?(c)
handle_session_reset(c)
Expand All @@ -18,18 +17,18 @@ def auto_session_timeout(seconds=nil)
end
end
end

def auto_session_timeout_actions
define_method(:active) { render_session_status }
define_method(:timeout) { render_session_timeout }
end
end

def render_session_status
response.headers["Etag"] = nil # clear etags to prevent caching
render plain: !!current_user, status: 200
end

def render_session_timeout
flash[:notice] = t("devise.failure.timeout", default: "Your session has timed out.")
redirect_to sign_in_path
Expand All @@ -54,7 +53,7 @@ def sign_in_path
rescue
"/login"
end

end

ActionController::Base.send :include, AutoSessionTimeout

0 comments on commit 0fa1d9f

Please sign in to comment.