Generate API key during auto-sync after upgrade

Fixes #1086, Sync settings/auto-sync glitch after Standalone upgrade
This commit is contained in:
Dan Stillman 2016-09-05 03:20:29 -04:00
parent c01fc5d762
commit 008321bb89
2 changed files with 24 additions and 26 deletions

View file

@ -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';

View file

@ -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()
})
}