From d6c26087d806aee13f59e499e3cc7effbf2050e4 Mon Sep 17 00:00:00 2001 From: juanfran Date: Thu, 3 Nov 2016 10:22:00 +0100 Subject: [PATCH] prevent infinite loop with an invalid token --- app/coffee/app.coffee | 5 ++++- app/coffee/modules/auth.coffee | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index cc5a7a99..cca4eae4 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -529,7 +529,10 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven .search("force_next", search.force_next) else $location.url($navUrls.resolve("login")) - .search("next", nextUrl) + .search({ + "unauthorized": true + "next": nextUrl + }) return $q.reject(response) diff --git a/app/coffee/modules/auth.coffee b/app/coffee/modules/auth.coffee index def65a3c..814e8323 100644 --- a/app/coffee/modules/auth.coffee +++ b/app/coffee/modules/auth.coffee @@ -32,10 +32,11 @@ class LoginPage 'tgCurrentUserService', '$location', '$tgNavUrls', - '$routeParams' + '$routeParams', + '$tgAuth' ] - constructor: (currentUserService, $location, $navUrls, $routeParams) -> + constructor: (currentUserService, $location, $navUrls, $routeParams, $auth) -> if currentUserService.isAuthenticated() if not $routeParams['force_login'] url = $navUrls.resolve("home") @@ -43,7 +44,11 @@ class LoginPage url = decodeURIComponent($routeParams['next']) $location.search('next', null) - $location.url(url) + if $routeParams['unauthorized'] + $auth.clear() + $auth.removeToken() + else + $location.url(url) module.controller('LoginPage', LoginPage)