Fix storage of Wikibase credentials, to be updated with better serialization later on
This commit is contained in:
parent
ab642a52a1
commit
1c51b32458
@ -46,6 +46,7 @@ public class ConnectionManager {
|
|||||||
private ConnectionManager() {
|
private ConnectionManager() {
|
||||||
prefStore = ProjectManager.singleton.getPreferenceStore();
|
prefStore = ProjectManager.singleton.getPreferenceStore();
|
||||||
connection = null;
|
connection = null;
|
||||||
|
restoreSavedConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void login(String username, String password, boolean rememberCredentials) {
|
public void login(String username, String password, boolean rememberCredentials) {
|
||||||
@ -71,10 +72,22 @@ public class ConnectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void restoreSavedConnection() {
|
||||||
|
JSONObject savedCredentials = getStoredCredentials();
|
||||||
|
if (savedCredentials != null) {
|
||||||
|
connection = ApiConnection.getWikidataApiConnection();
|
||||||
|
try {
|
||||||
|
connection.login(savedCredentials.getString("username"),
|
||||||
|
savedCredentials.getString("password"));
|
||||||
|
} catch (LoginFailedException e) {
|
||||||
|
connection = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject getStoredCredentials() {
|
public JSONObject getStoredCredentials() {
|
||||||
JSONArray array = (JSONArray) prefStore.get(PREFERENCE_STORE_KEY);
|
JSONArray array = (JSONArray) prefStore.get(PREFERENCE_STORE_KEY);
|
||||||
if (array.length() > 0) {
|
if (array.length() > 0) {
|
||||||
JSONObject obj;
|
|
||||||
try {
|
try {
|
||||||
return array.getJSONObject(0);
|
return array.getJSONObject(0);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user