Kill inactive sessions after 5 minutes

This commit is contained in:
Martin Lensment 2015-05-20 21:24:31 +03:00
parent 6a63c258f6
commit 45d62b8f6e

View file

@ -5,6 +5,7 @@ class EppController < ApplicationController
before_action :generate_svtrid
before_action :validate_request
before_action :update_epp_session
helper_method :current_user
rescue_from CanCan::AccessDenied do |_exception|
@ -35,6 +36,26 @@ class EppController < ApplicationController
EppSession.find_or_initialize_by(session_id: cookie['session'])
end
def update_epp_session
e_s = epp_session
return if e_s.new_record?
if e_s.updated_at < Time.zone.now - 5.minutes
@api_user = current_user # cache current_user for logging
e_s.destroy
response.headers['X-EPP-Returncode'] = '1500'
epp_errors << {
msg: t('session_timeout'),
code: '2201'
}
handle_errors and return
else
e_s.update_column(:updated_at, Time.zone.now)
end
end
def current_user
@current_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
# by default PaperTrail uses before filter and at that