Commit f6db2d51 authored by Randall Leeds's avatar Randall Leeds

Delay authentication timeout on scope updates

Fix two issues with the authentication timeouts.

- Fix #1284, the regression causing resets to always occur, introduced
  by e4f32116fe5f266e2030a666f5cc912b6b3df308
- Flash a message when the reset happens. Close #1280
- Increased the timeout to five minutes, as per suggestion by @dwhly
parent 7d818028
......@@ -34,26 +34,47 @@ class App
this.$inject = [
'$element', '$filter', '$http', '$location', '$rootScope', '$scope', '$timeout',
'annotator', 'session', 'socket', 'streamfilter', 'viewFilter'
'annotator', 'flash', 'session', 'socket', 'streamfilter', 'viewFilter'
]
constructor: (
$element, $filter, $http, $location, $rootScope, $scope, $timeout
annotator, session, socket, streamfilter, viewFilter
annotator, flash, session, socket, streamfilter, viewFilter
) ->
{plugins, host, providers} = annotator
_authTimeout = null
_reset = =>
delete annotator.ongoing_edit
base = angular.copy @scope
angular.extend $scope, base,
frame: $scope.frame or @scope.frame
socialView: annotator.socialView
ongoingHighlightSwitch: false
_startAuthTimeout = ->
# Reset the auth forms after five minutes of inactivity
if _authTimeout
$timeout.cancel _authTimeout
_authTimeout = $timeout ->
# Skip the reset if we're logged in
unless $scope.model.persona
$scope.$broadcast 'reset'
flash 'info',
'For your security, the forms have been reset due to inactivity.'
, 300000
_reset()
session.$promise.then (data) ->
angular.extend $scope.model, data
$scope.$watchCollection 'model', ->
# (Re)start (i.e., delay) the authentication form timeout
unless $scope.sheet.collapsed
_startAuthTimeout()
$scope.$watch 'model.personas', (newValue, oldValue) =>
if newValue?.length
unless $scope.model.persona and $scope.model.persona in newValue
......@@ -125,17 +146,7 @@ class App
$scope.$watch 'sheet.collapsed', (hidden) ->
$scope.sheet.tab = if hidden then null else 'login'
authTimeout = null
$scope.$watch 'sheet.tab', (tab) ->
if authTimeout
$timeout.cancel authTimeout
unless $scope.model.persona
authTimeout = $timeout (-> $scope.$broadcast 'reset'), 60000
unless tab
$scope.ongoingHighlightSwitch = false
delete annotator.ongoing_edit
$timeout ->
$element
.find('form')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment