commit 008321bb8984485ade04d928b65ab65ed2183579
parent c01fc5d76274261e8d20c0af775581745b425177
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 5 Sep 2016 03:20:29 -0400
Generate API key during auto-sync after upgrade
Fixes #1086, Sync settings/auto-sync glitch after Standalone upgrade
Diffstat:
2 files changed, 24 insertions(+), 26 deletions(-)
diff --git 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
@@ -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()
})
}