Commit 21898533 authored by Randall Leeds's avatar Randall Leeds

Move auth timeout into Auth controller

parent 8fe7dac7
...@@ -42,8 +42,6 @@ class App ...@@ -42,8 +42,6 @@ class App
) -> ) ->
{plugins, host, providers} = annotator {plugins, host, providers} = annotator
_authTimeout = null
_reset = => _reset = =>
delete annotator.ongoing_edit delete annotator.ongoing_edit
base = angular.copy @scope base = angular.copy @scope
...@@ -52,19 +50,6 @@ class App ...@@ -52,19 +50,6 @@ class App
socialView: annotator.socialView socialView: annotator.socialView
ongoingHighlightSwitch: false 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() _reset()
annotator.subscribe 'serviceDiscovery', (options) -> annotator.subscribe 'serviceDiscovery', (options) ->
...@@ -85,11 +70,6 @@ class App ...@@ -85,11 +70,6 @@ class App
$i.triggerHandler('input') $i.triggerHandler('input')
, 200 # We hope this is long enough , 200 # We hope this is long enough
$scope.$watchCollection 'model', ->
# (Re)start (i.e., delay) the authentication form timeout
unless $scope.sheet.collapsed
_startAuthTimeout()
$scope.$watch 'model.personas', (newValue, oldValue) => $scope.$watch 'model.personas', (newValue, oldValue) =>
if newValue?.length if newValue?.length
unless $scope.model.persona and $scope.model.persona in newValue unless $scope.model.persona and $scope.model.persona in newValue
...@@ -191,6 +171,13 @@ class App ...@@ -191,6 +171,13 @@ class App
filter = streamfilter.getFilter() filter = streamfilter.getFilter()
sock.send(JSON.stringify({filter})) sock.send(JSON.stringify({filter}))
$scope.$on 'authTimeout', ->
# 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.'
$scope.$on 'showAuth', (event, show=true) -> $scope.$on 'showAuth', (event, show=true) ->
$scope.sheet.collapsed = !show $scope.sheet.collapsed = !show
...@@ -698,14 +685,16 @@ class Annotation ...@@ -698,14 +685,16 @@ class Annotation
class Auth class Auth
this.$inject = ['$scope', 'session'] this.$inject = ['$scope', '$timeout', 'session']
constructor: ( $scope, session) -> constructor: ( $scope, $timeout, session) ->
base = base =
username: null username: null
email: null email: null
password: null password: null
code: null code: null
_timeout = null
_reset = -> _reset = ->
delete $scope.errors delete $scope.errors
angular.extend $scope.model, base angular.extend $scope.model, base
...@@ -719,8 +708,18 @@ class Auth ...@@ -719,8 +708,18 @@ class Auth
for field, error of errors for field, error of errors
$scope.errors[form][field] = error $scope.errors[form][field] = error
_startTimeout = ->
# Reset the auth forms after five minutes of inactivity
if _timeout then $timeout.cancel _timeout
_timeout = $timeout (-> $scope.$emit 'authTimeout'), 3000000
$scope.$on 'reset', _reset $scope.$on 'reset', _reset
$scope.$watchCollection 'model', ->
# (Re)start (i.e., delay) the authentication form timeout
unless $scope.sheet.collapsed
_startTimeout()
$scope.submit = (form) -> $scope.submit = (form) ->
angular.extend session, $scope.model angular.extend session, $scope.model
return unless form.$valid return unless form.$valid
......
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