Commit 2e188a0ce23e20315d58efa5bd3e4504717145ad
1 parent
8591c23c
Exists in
master
and in
38 other branches
Improve login/logout flow
Showing
3 changed files
with
14 additions
and
4 deletions
Show diff stats
gulp/server.js
| @@ -30,6 +30,7 @@ function browserSyncInit(baseDir, browser) { | @@ -30,6 +30,7 @@ function browserSyncInit(baseDir, browser) { | ||
| 30 | proxyMiddleware('http://localhost:3000/myprofile', {changeOrigin:true}), | 30 | proxyMiddleware('http://localhost:3000/myprofile', {changeOrigin:true}), |
| 31 | proxyMiddleware('http://localhost:3000/designs', {changeOrigin:true}), | 31 | proxyMiddleware('http://localhost:3000/designs', {changeOrigin:true}), |
| 32 | proxyMiddleware('http://localhost:3000/image_uploads', {changeOrigin:true}), | 32 | proxyMiddleware('http://localhost:3000/image_uploads', {changeOrigin:true}), |
| 33 | + proxyMiddleware('http://localhost:3000/account/logout', {changeOrigin:true}), | ||
| 33 | proxyMiddleware('http://localhost:3000/images', {changeOrigin:true})]; | 34 | proxyMiddleware('http://localhost:3000/images', {changeOrigin:true})]; |
| 34 | // proxyMiddleware('http://localhost:3000/assets', {changeOrigin:true})]; | 35 | // proxyMiddleware('http://localhost:3000/assets', {changeOrigin:true})]; |
| 35 | 36 |
src/app/components/auth/auth.service.js
| @@ -36,6 +36,7 @@ | @@ -36,6 +36,7 @@ | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | function logout () { | 38 | function logout () { |
| 39 | + $http.jsonp('/account/logout'); //FIXME logout from noosfero to sync login state | ||
| 39 | Session.destroy(); | 40 | Session.destroy(); |
| 40 | $rootScope.currentUser = undefined; | 41 | $rootScope.currentUser = undefined; |
| 41 | $rootScope.$broadcast(AUTH_EVENTS.logoutSuccess); | 42 | $rootScope.$broadcast(AUTH_EVENTS.logoutSuccess); |
src/app/components/navbar/navbar.directive.js
| @@ -27,21 +27,29 @@ | @@ -27,21 +27,29 @@ | ||
| 27 | // "vm.creation" is avaible by directive option "bindToController: true" | 27 | // "vm.creation" is avaible by directive option "bindToController: true" |
| 28 | vm.relativeDate = moment(vm.creationDate).fromNow(); | 28 | vm.relativeDate = moment(vm.creationDate).fromNow(); |
| 29 | vm.currentUser = Session.getCurrentUser(); | 29 | vm.currentUser = Session.getCurrentUser(); |
| 30 | + vm.modalInstance = null; | ||
| 30 | 31 | ||
| 31 | vm.openLogin = function() { | 32 | vm.openLogin = function() { |
| 32 | - var modalInstance = $modal.open({ | 33 | + vm.modalInstance = $modal.open({ |
| 33 | templateUrl: 'app/components/auth/login.html', | 34 | templateUrl: 'app/components/auth/login.html', |
| 34 | controller: 'AuthController', | 35 | controller: 'AuthController', |
| 35 | controllerAs: 'vm', | 36 | controllerAs: 'vm', |
| 36 | bindToController: true | 37 | bindToController: true |
| 37 | }); | 38 | }); |
| 38 | - $scope.$on(AUTH_EVENTS.loginSuccess, function() { | ||
| 39 | - modalInstance.close(); | ||
| 40 | - }); | ||
| 41 | }; | 39 | }; |
| 42 | vm.logout = function() { | 40 | vm.logout = function() { |
| 43 | AuthService.logout(); | 41 | AuthService.logout(); |
| 44 | }; | 42 | }; |
| 43 | + $scope.$on(AUTH_EVENTS.loginSuccess, function() { | ||
| 44 | + if(vm.modalInstance) { | ||
| 45 | + vm.modalInstance.close(); | ||
| 46 | + vm.modalInstance = null; | ||
| 47 | + } | ||
| 48 | + vm.currentUser = Session.getCurrentUser(); | ||
| 49 | + }); | ||
| 50 | + $scope.$on(AUTH_EVENTS.logoutSuccess, function() { | ||
| 51 | + vm.currentUser = Session.getCurrentUser(); | ||
| 52 | + }); | ||
| 45 | } | 53 | } |
| 46 | } | 54 | } |
| 47 | 55 |