Skip to content

Commit

Permalink
Async logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy E. Johansson committed Apr 17, 2014
1 parent cd9aec3 commit 35aea90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Logged in users who try to access the route without the proper permissions will

## Loaders

All directives except `ua-logout` sets the scope variable `loading` to `true` while it's doing work in the background. This way you could show a loader animation while waiting for the UserApp API to respond. Here's an example with the login form:
All directives sets the scope variable `loading` to `true` while it's doing work in the background. This way you could show a loader animation while waiting for the UserApp API to respond. Here's an example with the login form:

```html
<form ua-login>
Expand Down
29 changes: 23 additions & 6 deletions angularjs.userapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,15 @@ var userappModule = angular.module('UserApp', []);
that.reset();
});
} else {*/
UserApp.User.logout(function(error) {});
that.reset();
UserApp.User.logout(function(error) {
that.reset();
$rootScope.$broadcast('user.logout');
callback && callback(error);
});
//}

$rootScope.$broadcast('user.logout');
callback && callback(error);
//$rootScope.$broadcast('user.logout');
//callback && callback(error);
},

// Send reset password email
Expand Down Expand Up @@ -530,13 +533,27 @@ var userappModule = angular.module('UserApp', []);
});

// Logout directive
userappModule.directive('uaLogout', function(user) {
userappModule.directive('uaLogout', function($timeout, user) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var evHandler = function(e) {
e.preventDefault();
user.logout();

if (scope.loading) {
return false;
}

$timeout(function() {
scope.loading = true;
});

user.logout(function() {
$timeout(function() {
scope.loading = false;
});
});

return false;
};

Expand Down

0 comments on commit 35aea90

Please sign in to comment.