Simplifies user service to launch the dialog and clear user data, updates the login dialog to show that their session has expired when it has expired (not during initial login)

This commit is contained in:
Shannon
2013-10-16 13:49:50 +11:00
parent 6400e7988f
commit cb727bf6e6
2 changed files with 28 additions and 26 deletions

View File

@@ -14,14 +14,17 @@ angular.module('umbraco.services')
$location.path(url);
}
function openLoginDialog() {
function openLoginDialog(isTimedOut) {
if (!loginDialog) {
loginDialog = dialogService.open({
template: 'views/common/dialogs/login.html',
modalClass: "login-overlay",
animation: "slide",
show: true,
callback: onLoginDialogClose
callback: onLoginDialogClose,
dialogData: {
isTimedOut: isTimedOut
}
});
}
}
@@ -88,12 +91,8 @@ angular.module('umbraco.services')
}
else {
//we are either timed out or very close to timing out so we need to show the login dialog.
//first reset these flags so the timer does not continue, it will be started automatically when
// the user logs in again.
currentUser.remainingAuthSeconds = 0;
lastServerTimeoutSet = null;
openLoginDialog();
//we are either timed out or very close to timing out so we need to show the login dialog.
userAuthExpired();
}
}
}, 2000);//every 2 seconds
@@ -107,21 +106,27 @@ angular.module('umbraco.services')
lastServerTimeoutSet = new Date();
}
}
/** resets all user data, broadcasts the notAuthenticated event and shows the login dialog */
function userAuthExpired() {
//store the last user id and clear the user
if (currentUser && currentUser.id !== undefined) {
lastUserId = currentUser.id;
}
currentUser.remainingAuthSeconds = 0;
lastServerTimeoutSet = null;
currentUser = null;
//broadcast a global event that the user is no longer logged in
$rootScope.$broadcast("notAuthenticated");
openLoginDialog(true);
}
// Register a handler for when an item is added to the retry queue
securityRetryQueue.onItemAddedCallbacks.push(function (retryItem) {
if (securityRetryQueue.hasMore()) {
//store the last user id and clear the user
if (currentUser && currentUser.id !== undefined) {
lastUserId = currentUser.id;
}
currentUser = null;
//broadcast a global event that the user is no longer logged in
$rootScope.$broadcast("notAuthenticated");
openLoginDialog();
userAuthExpired();
}
});
@@ -164,13 +169,9 @@ angular.module('umbraco.services')
/** Logs the user out and redirects to the login page */
logout: function () {
return authResource.performLogout()
.then(function (data) {
.then(function (data) {
lastUserId = currentUser.id;
currentUser = null;
//broadcast a global event
$rootScope.$broadcast("notAuthenticated");
userAuthExpired();
$location.path("/login").search({check: false});

View File

@@ -1,7 +1,8 @@
<form name="loginForm" ng-submit="loginSubmit(login, password)" ng-controller="Umbraco.Dialogs.LoginController">
<div id="login" class="umb-modalcolumn" ng-class="{'show-validation': loginForm.$invalid}">
<div class="form">
<h1>Happy {{today}}!, log in below</h1>
<h1>Happy {{today}}!</h1>
<p><span ng-show="dialogData.isTimedOut">Session timed out. </span>Log in below</p>
<div class="control-group" ng-class="{error: loginForm.username.$invalid}">
<input type="text" ng-model="login" name="username" class="input-xlarge" placeholder="Enter your username" />