Patch #15234 » session_expired_popup_message.diff
| config/routes.rb (working copy) | ||
|---|---|---|
|
RedmineApp::Application.routes.draw do
|
||
|
root :to => 'welcome#index', :as => 'home'
|
||
|
|
||
|
get '/session_heartbeat', :to => 'application#session_heartbeat'
|
||
|
match 'login', :to => 'account#login', :as => 'signin', :via => [:get, :post]
|
||
|
match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post]
|
||
| public/javascripts/application.js (working copy) | ||
|---|---|---|
|
$(document).ready(setupAjaxIndicator);
|
||
|
$(document).ready(hideOnLoad);
|
||
|
$(document).ready(addFormObserversForDoubleSubmit);
|
||
|
function SessionHeartbeat() {
|
||
|
$.ajax( {
|
||
|
url: '/session_heartbeat',
|
||
|
success: function(data) {
|
||
|
if(data.expired) {
|
||
|
alert(data.message);
|
||
|
}
|
||
|
else if(data.remain > 0) {
|
||
|
setTimeout(SessionHeartbeat, data.remain);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
|
unless User.current.pref.warn_on_leaving_unsaved == '0'
|
||
|
tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
|
||
|
end
|
||
|
if User.current && (!User.current.anonymous?) && (Setting.session_timeout || Setting.session_lifetime)
|
||
|
lifetime = Setting.session_lifetime ? Setting.session_lifetime.to_i : 0
|
||
|
timeout = Setting.session_timeout ? Setting.session_timeout.to_i : 0
|
||
|
timeout = lifetime if lifetime > 0 && lifetime < timeout
|
||
|
unless timeout == 0
|
||
|
tags << "\n".html_safe + javascript_tag("setTimeout(SessionHeartbeat, #{timeout * 60000});")
|
||
|
end
|
||
|
end
|
||
|
tags
|
||
|
end
|
||
| app/controllers/application_controller.rb (working copy) | ||
|---|---|---|
|
include Redmine::MenuManager::MenuController
|
||
|
helper Redmine::MenuManager::MenuHelper
|
||
|
def session_heartbeat
|
||
|
remain = 0
|
||
|
if Setting.session_lifetime? && session[:ctime]
|
||
|
remain = (Setting.session_lifetime.to_i * 60) - (Time.now.utc.to_i - session[:ctime].to_i)
|
||
|
end
|
||
|
if Setting.session_timeout? && session[:atime]
|
||
|
if remain > 0
|
||
|
remain = [remain, (Setting.session_timeout.to_i * 60) - (Time.now.utc.to_i - session[:atime].to_i)].min
|
||
|
else
|
||
|
remain = (Setting.session_timeout.to_i * 60) - (Time.now.utc.to_i - session[:atime].to_i)
|
||
|
end
|
||
|
end
|
||
|
if session_expired? || remain <= 0
|
||
|
render json: { expired: true, message: l(:error_session_expired) }
|
||
|
else
|
||
|
render json: { expired: false, remain: (remain * 1000) }
|
||
|
end
|
||
|
end
|
||
|
def session_expiration
|
||
|
# Skip session heartbeat
|
||
|
return if ((params[:controller] == 'application') && (params[:action] = 'session_heartbeat'))
|
||
|
if session[:user_id]
|
||
|
if session_expired? && !try_to_autologin
|
||
|
reset_session
|
||