diff options
author | Emmanuel ROHEE <erohee@amdocs.com> | 2014-08-14 14:59:33 +0200 |
---|---|---|
committer | Emmanuel ROHEE <erohee@amdocs.com> | 2014-08-14 15:00:21 +0200 |
commit | 7143f358f1487d4044cc5ad64056f621a5aa2139 (patch) | |
tree | d3387b1161691bbe7918ddca5d86bde88f7d9210 | |
parent | Guess the home server URL on the login screen by inspecting the URL of the we... (diff) | |
download | synapse-7143f358f1487d4044cc5ad64056f621a5aa2139.tar.xz |
Detect when the user access token is no more valid and log the user out in this case
-rw-r--r-- | webclient/app-controller.js | 10 | ||||
-rw-r--r-- | webclient/components/matrix/matrix-service.js | 14 |
2 files changed, 20 insertions, 4 deletions
diff --git a/webclient/app-controller.js b/webclient/app-controller.js index 41055bdcd2..086fa3d946 100644 --- a/webclient/app-controller.js +++ b/webclient/app-controller.js @@ -55,8 +55,14 @@ angular.module('MatrixWebClientController', ['matrixService']) // And go to the login page $location.path("login"); - }; - + }; + + // Listen to the event indicating that the access token is no more valid. + // In this case, the user needs to log in again. + $scope.$on("M_UNKNOWN_TOKEN", function() { + console.log("Invalid access token -> log user out"); + $scope.logout(); + }); }]); \ No newline at end of file diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index f054bf301e..81ccdc2cc0 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -17,7 +17,7 @@ limitations under the License. 'use strict'; angular.module('matrixService', []) -.factory('matrixService', ['$http', '$q', function($http, $q) { +.factory('matrixService', ['$http', '$q', '$rootScope', function($http, $q, $rootScope) { /* * Permanent storage of user information @@ -60,7 +60,6 @@ angular.module('matrixService', []) headers: headers }) .success(function(data, status, headers, config) { - // @TODO: We could detect a bad access token here and make an automatic logout deferred.resolve(data, status, headers, config); }) .error(function(data, status, headers, config) { @@ -70,6 +69,11 @@ angular.module('matrixService', []) reason = JSON.stringify(data); } deferred.reject(reason, data, status, headers, config); + + if (403 === status && "M_UNKNOWN_TOKEN" === data.errcode) { + // The access token is no more valid, broadcast the issue + $rootScope.$broadcast("M_UNKNOWN_TOKEN"); + } }); return deferred.promise; @@ -301,6 +305,12 @@ angular.module('matrixService', []) return doBaseRequest(config.identityServer, "POST", path, {}, data, headers); }, + + // + testLogin: function() { + + }, + /****** Permanent storage of user information ******/ // Returns the current config |