From e3dea4084fbbb67fd81aa8921071a8e68d1ecf07 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 3 Nov 2017 15:40:19 -0400 Subject: [PATCH] fix callbacks for user service methods --- src/background.js | 26 +++++++++--------- src/popup/app/config.js | 28 +++++++++++--------- src/popup/app/lock/lockController.js | 2 +- src/popup/app/tools/toolsExportController.js | 2 +- src/services/syncService.js | 2 +- src/services/user.service.ts | 3 --- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/background.js b/src/background.js index 1a3e45db..c573fd68 100644 --- a/src/background.js +++ b/src/background.js @@ -436,19 +436,21 @@ var bg_isBackground = true, return; } - bg_userService.isAuthenticated(function (isAuthenticated) { - bg_cryptoService.getKey().then(function (key) { - var suffix = ''; - if (!isAuthenticated) { - suffix = '_gray'; - } - else if (!key) { - suffix = '_locked'; - } + var isAuthenticated; + bg_userService.isAuthenticated().then(function (theIsAuthenticated) { + isAuthenticated = theIsAuthenticated; + return bg_cryptoService.getKey(); + }).then(function (key) { + var suffix = ''; + if (!isAuthenticated) { + suffix = '_gray'; + } + else if (!key) { + suffix = '_locked'; + } - actionSetIcon(chrome.browserAction, suffix); - actionSetIcon(bg_sidebarAction, suffix); - }); + actionSetIcon(chrome.browserAction, suffix); + actionSetIcon(bg_sidebarAction, suffix); }); function actionSetIcon(theAction, suffix) { diff --git a/src/popup/app/config.js b/src/popup/app/config.js index b5b29d9c..176c19f2 100644 --- a/src/popup/app/config.js +++ b/src/popup/app/config.js @@ -23,20 +23,22 @@ angular var userService = $injector.get('userService'); var cryptoService = $injector.get('cryptoService'); - cryptoService.getKey().then(function (key) { - userService.isAuthenticated(function (isAuthenticated) { - if (isAuthenticated) { - if (!key) { - $state.go('lock'); - } - else { - $state.go('tabs.current'); - } + var key; + cryptoService.getKey().then(function (theKey) { + key = theKey; + return userService.isAuthenticated(); + }).then(function (isAuthenticated) { + if (isAuthenticated) { + if (!key) { + $state.go('lock'); } else { - $state.go('home'); + $state.go('tabs.current'); } - }); + } + else { + $state.go('home'); + } }); }); @@ -269,7 +271,7 @@ angular stateService.init(); - $transitions.onStart({}, function(trans) { + $transitions.onStart({}, function (trans) { const $state = trans.router.stateService; const toState = trans.to(); @@ -284,7 +286,7 @@ angular return; } - userService.isAuthenticated((isAuthenticated) => { + userService.isAuthenticated().then((isAuthenticated) => { if (isAuthenticated) { var obj = {}; obj[constantsService.lastActiveKey] = (new Date()).getTime(); diff --git a/src/popup/app/lock/lockController.js b/src/popup/app/lock/lockController.js index d185f68c..157ae9de 100644 --- a/src/popup/app/lock/lockController.js +++ b/src/popup/app/lock/lockController.js @@ -24,7 +24,7 @@ angular }; $scope.submit = function () { - userService.getEmail(function (email) { + userService.getEmail().then(function (email) { var key = cryptoService.makeKey($scope.masterPassword, email); var keyHash; cryptoService.hashPassword($scope.masterPassword, key).then(function (theKeyHash) { diff --git a/src/popup/app/tools/toolsExportController.js b/src/popup/app/tools/toolsExportController.js index d03bb2e6..5a366596 100644 --- a/src/popup/app/tools/toolsExportController.js +++ b/src/popup/app/tools/toolsExportController.js @@ -22,7 +22,7 @@ angular function checkPassword() { var deferred = $q.defer(); - userService.getEmail(function (email) { + userService.getEmail().then(function (email) { var key = cryptoService.makeKey($scope.masterPassword, email); var keyHash; cryptoService.hashPassword($scope.masterPassword, key).then(function (theKeyHash) { diff --git a/src/services/syncService.js b/src/services/syncService.js index 4c4172e8..2ffb7c33 100644 --- a/src/services/syncService.js +++ b/src/services/syncService.js @@ -21,7 +21,7 @@ function initSyncService() { var self = this; self.syncStarted(); - self.userService.isAuthenticated(function (isAuthenticated) { + self.userService.isAuthenticated().then(function (isAuthenticated) { if (!isAuthenticated) { self.syncCompleted(false); callback(false); diff --git a/src/services/user.service.ts b/src/services/user.service.ts index 6a405906..060eb782 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -31,7 +31,6 @@ export default class UserService { return UtilsService.saveObjToStorage(Keys.stamp, stamp); } - // TODO: callbacks async getUserId(): Promise { if (this.userId != null) { return this.userId; @@ -41,7 +40,6 @@ export default class UserService { return this.userId; } - // TODO: callbacks async getEmail(): Promise { if (this.email != null) { return this.email; @@ -70,7 +68,6 @@ export default class UserService { this.userId = this.email = this.stamp = null; } - // TODO: fix callbacks async isAuthenticated(): Promise { const token = await this.tokenService.getToken(); if (token == null) {