@@ -3,6 +3,7 @@ angular.module('umbraco.services')
3
3
4
4
var currentUser = null ;
5
5
var lastUserId = null ;
6
+ var countdownCounter = null ;
6
7
7
8
//this tracks the last date/time that the user's remainingAuthSeconds was updated from the server
8
9
// this is used so that we know when to go and get the user's remaining seconds directly.
@@ -43,6 +44,10 @@ angular.module('umbraco.services')
43
44
}
44
45
currentUser = usr ;
45
46
lastServerTimeoutSet = new Date ( ) ;
47
+ //don't start the timer if it is already going
48
+ if ( countdownCounter ) {
49
+ return ;
50
+ }
46
51
//start the timer
47
52
countdownUserTimeout ( ) ;
48
53
}
@@ -54,7 +59,7 @@ angular.module('umbraco.services')
54
59
*/
55
60
function countdownUserTimeout ( ) {
56
61
57
- $timeout ( function ( ) {
62
+ countdownCounter = $timeout ( function ( ) {
58
63
59
64
if ( currentUser ) {
60
65
//countdown by 5 seconds since that is how long our timer is for.
@@ -95,15 +100,20 @@ angular.module('umbraco.services')
95
100
if ( Umbraco . Sys . ServerVariables . umbracoSettings . keepUserLoggedIn !== true ) {
96
101
//NOTE: the safeApply because our timeout is set to not run digests (performance reasons)
97
102
angularHelper . safeApply ( $rootScope , function ( ) {
98
- try {
99
- //NOTE: We are calling this again so that the server can create a log that the timeout has expired, we
100
- // don't actually care about this result.
101
- authResource . getRemainingTimeoutSeconds ( ) ;
102
- }
103
- finally {
104
- userAuthExpired ( ) ;
105
- }
103
+ //NOTE: We are calling this again so that the server can create a log that the timeout has expired
104
+ //and we will show the login screen as close to the server's timout time as possible
105
+ authResource . getRemainingTimeoutSeconds ( ) . then ( function ( result ) {
106
+ setUserTimeoutInternal ( result ) ;
107
+
108
+ //the client auth can expire a second earlier as the client internal clock is behind
109
+ if ( result < 1 ) {
110
+ userAuthExpired ( ) ;
111
+ }
112
+ } ) ;
106
113
} ) ;
114
+
115
+ //recurse the countdown!
116
+ countdownUserTimeout ( ) ;
107
117
}
108
118
else {
109
119
//we've got less than 30 seconds remaining so let's check the server
@@ -155,6 +165,7 @@ angular.module('umbraco.services')
155
165
156
166
lastServerTimeoutSet = null ;
157
167
currentUser = null ;
168
+ countdownCounter = null ;
158
169
159
170
if ( ! isLogout ) {
160
171
openLoginDialog ( true ) ;
0 commit comments