Project

General

Profile

Patch #15234 » session_expired_popup_message.diff

Karel Pičman, 2013-10-31 17:19

View differences:

config/routes.rb (working copy)
17 17

  
18 18
RedmineApp::Application.routes.draw do
19 19
  root :to => 'welcome#index', :as => 'home'
20
  
21
  get '/session_heartbeat', :to => 'application#session_heartbeat'
20 22

  
21 23
  match 'login', :to => 'account#login', :as => 'signin', :via => [:get, :post]
22 24
  match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post]
public/javascripts/application.js (working copy)
591 591
$(document).ready(setupAjaxIndicator);
592 592
$(document).ready(hideOnLoad);
593 593
$(document).ready(addFormObserversForDoubleSubmit);
594

  
595
function SessionHeartbeat() {
596
    $.ajax( {
597
            url: '/session_heartbeat',
598
            success: function(data) {                                
599
                if(data.expired) {
600
                    alert(data.message);                       
601
                }
602
                else if(data.remain > 0) {
603
                    setTimeout(SessionHeartbeat, data.remain);
604
                }
605
            }             
606
        }
607
    );        
608
}
app/helpers/application_helper.rb (working copy)
1227 1227
    unless User.current.pref.warn_on_leaving_unsaved == '0'
1228 1228
      tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
1229 1229
    end
1230
    if User.current && (!User.current.anonymous?) && (Setting.session_timeout || Setting.session_lifetime)
1231
      lifetime = Setting.session_lifetime ? Setting.session_lifetime.to_i : 0
1232
      timeout = Setting.session_timeout ? Setting.session_timeout.to_i : 0
1233
      timeout = lifetime if lifetime > 0 && lifetime < timeout      
1234
      unless timeout == 0
1235
        tags << "\n".html_safe + javascript_tag("setTimeout(SessionHeartbeat, #{timeout * 60000});")
1236
      end
1237
    end
1230 1238
    tags
1231 1239
  end
1232 1240

  
app/controllers/application_controller.rb (working copy)
48 48
  include Redmine::MenuManager::MenuController
49 49
  helper Redmine::MenuManager::MenuHelper
50 50

  
51
  def session_heartbeat
52
    remain = 0
53
    if Setting.session_lifetime? && session[:ctime]
54
      remain = (Setting.session_lifetime.to_i * 60) - (Time.now.utc.to_i - session[:ctime].to_i)          
55
    end
56
    if Setting.session_timeout? && session[:atime]
57
      if remain > 0
58
        remain = [remain, (Setting.session_timeout.to_i * 60) - (Time.now.utc.to_i - session[:atime].to_i)].min
59
      else
60
        remain = (Setting.session_timeout.to_i * 60) - (Time.now.utc.to_i - session[:atime].to_i)
61
      end          
62
    end                
63
    if session_expired? || remain <= 0                
64
      render json: { expired: true, message: l(:error_session_expired) }
65
    else                        
66
      render json: { expired: false, remain: (remain * 1000) }
67
    end
68
  end
69

  
51 70
  def session_expiration
71
    # Skip session heartbeat
72
    return if ((params[:controller] == 'application') && (params[:action] = 'session_heartbeat'))
52 73
    if session[:user_id]
53 74
      if session_expired? && !try_to_autologin
54 75
        reset_session
(1-1/2)