| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import _ from 'lodash'; |
|
|
| import pgAdmin from 'sources/pgadmin'; |
| import pgWindow from 'sources/window'; |
| import {getEpoch} from 'sources/utils'; |
|
|
| const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; |
| const MIN_ACTIVITY_TIME_UNIT = 1000; |
| |
| |
| |
| _.extend(pgBrowser, { |
| inactivity_timeout_at: null, |
| logging_activity: false, |
| inactivity_timeout_daemon_running: false, |
|
|
| is_pgadmin_timedout: function() { |
| return !pgWindow.pgAdmin; |
| }, |
|
|
| is_inactivity_timeout: function() { |
| return pgWindow.pgAdmin.Browser.inactivity_timeout_at < this.get_epoch_now(); |
| }, |
|
|
| get_epoch_now: function(){ |
| return getEpoch(); |
| }, |
|
|
| log_activity: function() { |
| if(!this.logging_activity) { |
| this.logging_activity = true; |
| this.inactivity_timeout_at = this.get_epoch_now() + pgAdmin.user_inactivity_timeout; |
|
|
| |
| |
| |
| setTimeout(()=>{ |
| this.logging_activity = false; |
| }, MIN_ACTIVITY_TIME_UNIT); |
| } |
| }, |
|
|
| |
| |
| |
| register_to_activity_listener: function(target, timeout_callback) { |
| let inactivity_events = ['mousemove', 'mousedown', 'keydown']; |
| let self = this; |
| inactivity_events.forEach((event)=>{ |
| |
| let eventHandler = function() { |
| if(self.is_pgadmin_timedout()) { |
| |
| inactivity_events.forEach((events)=>{ |
| target.removeEventListener(events, eventHandler, true); |
| }); |
| timeout_callback(); |
| } else { |
| pgWindow.pgAdmin.Browser.log_activity(); |
| } |
| }; |
|
|
| target.addEventListener(event, eventHandler, true); |
| }); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| override_activity_event_decorator: function(input_func) { |
| return function() { |
| |
| if(pgAdmin.override_user_inactivity_timeout) { |
| pgWindow.pgAdmin.Browser.log_activity(); |
| } |
| return input_func.apply(this, arguments); |
| }; |
| }, |
|
|
| logout_inactivity_user: function() { |
| if (!_.isUndefined(pgBrowser.utils) && |
| !_.isUndefined(pgBrowser.utils.logout_url)) { |
| window.location.href = pgBrowser.utils.logout_url; |
| } |
| }, |
|
|
| |
| start_inactivity_timeout_daemon: function() { |
| let self = this; |
| if(pgAdmin.user_inactivity_timeout > 0 && !self.inactivity_timeout_daemon_running) { |
| let timeout_daemon_id = setInterval(()=>{ |
| self.inactivity_timeout_daemon_running = true; |
| if(self.is_inactivity_timeout()) { |
| clearInterval(timeout_daemon_id); |
| self.inactivity_timeout_daemon_running = false; |
| self.logout_inactivity_user(); |
| } |
| }, MIN_ACTIVITY_TIME_UNIT); |
| } |
| }, |
| }); |
|
|
| export {pgBrowser}; |
|
|