diff --git a/chrome/content/zotero/xpcom/sync/syncLocal.js b/chrome/content/zotero/xpcom/sync/syncLocal.js index 1608bdb4d..a684dd14c 100644 --- a/chrome/content/zotero/xpcom/sync/syncLocal.js +++ b/chrome/content/zotero/xpcom/sync/syncLocal.js @@ -43,9 +43,11 @@ Zotero.Sync.Data.Local = { getAPIKey: function () { - Zotero.debug("Getting API key"); var login = this._getAPIKeyLoginInfo(); - return login ? login.password : ""; + return login + ? login.password + // Fallback to old username/password + : this._getAPIKeyFromLogin(); }, @@ -348,6 +350,24 @@ Zotero.Sync.Data.Local = { }, + _getAPIKeyFromLogin: Zotero.Promise.coroutine(function* () { + let username = Zotero.Prefs.get('sync.server.username'); + if (username) { + // Check for legacy password if no password set in current session + // and no API keys stored yet + let password = this.getLegacyPassword(username); + if (!password) { + return ""; + } + + let json = yield Zotero.Sync.Runner.createAPIKeyFromCredentials(username, password); + this.removeLegacyLogins(); + return json.key; + } + return ""; + }), + + getLegacyPassword: function (username) { var loginManagerHost = 'chrome://zotero'; var loginManagerRealm = 'Zotero Sync Server'; diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 079270c3d..f8efc4ef4 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -1314,29 +1314,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { var _getAPIKey = Zotero.Promise.coroutine(function* () { - // Set as .apiKey on Runner in tests - return _apiKey - // Set in login manager - || Zotero.Sync.Data.Local.getAPIKey() - // Fallback to old username/password - || _getAPIKeyFromLogin(); - }) - - - var _getAPIKeyFromLogin = Zotero.Promise.coroutine(function* () { - let username = Zotero.Prefs.get('sync.server.username'); - if (username) { - // Check for legacy password if no password set in current session - // and no API keys stored yet - let password = Zotero.Sync.Data.Local.getLegacyPassword(username); - if (!password) { - return ""; - } - - let json = yield Zotero.Sync.Runner.createAPIKeyFromCredentials(username, password); - Zotero.Sync.Data.Local.removeLegacyLogins(); - return json.key; - } - return ""; + // Set as .apiKey on Runner in tests or set in login manager + return _apiKey || Zotero.Sync.Data.Local.getAPIKey() }) }