Skip to content

Commit 2ad5ecd

Browse files
elit0451Zeegaan
authored andcommitted
Make sure that the client shows the login screen as close to the server's timout time as possible
1 parent 97d74f3 commit 2ad5ecd

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/Umbraco.Web.UI.Client/src/common/services/user.service.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ angular.module('umbraco.services')
33

44
var currentUser = null;
55
var lastUserId = null;
6+
var countdownCounter = null;
67

78
//this tracks the last date/time that the user's remainingAuthSeconds was updated from the server
89
// 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')
4344
}
4445
currentUser = usr;
4546
lastServerTimeoutSet = new Date();
47+
//don't start the timer if it is already going
48+
if (countdownCounter) {
49+
return;
50+
}
4651
//start the timer
4752
countdownUserTimeout();
4853
}
@@ -54,7 +59,7 @@ angular.module('umbraco.services')
5459
*/
5560
function countdownUserTimeout() {
5661

57-
$timeout(function () {
62+
countdownCounter = $timeout(function () {
5863

5964
if (currentUser) {
6065
//countdown by 5 seconds since that is how long our timer is for.
@@ -95,15 +100,20 @@ angular.module('umbraco.services')
95100
if (Umbraco.Sys.ServerVariables.umbracoSettings.keepUserLoggedIn !== true) {
96101
//NOTE: the safeApply because our timeout is set to not run digests (performance reasons)
97102
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+
});
106113
});
114+
115+
//recurse the countdown!
116+
countdownUserTimeout();
107117
}
108118
else {
109119
//we've got less than 30 seconds remaining so let's check the server
@@ -155,6 +165,7 @@ angular.module('umbraco.services')
155165

156166
lastServerTimeoutSet = null;
157167
currentUser = null;
168+
countdownCounter = null;
158169

159170
if (!isLogout) {
160171
openLoginDialog(true);

0 commit comments

Comments
 (0)