@@ -18,6 +17,10 @@
Password:
+
+
+ Remember credentials (stored unencrypted in OpenRefine's preferences)
+
diff --git a/extensions/wikidata/module/scripts/dialogs/manage-account-dialog.js b/extensions/wikidata/module/scripts/dialogs/manage-account-dialog.js
index 72c20f6f4..5d2cddb63 100644
--- a/extensions/wikidata/module/scripts/dialogs/manage-account-dialog.js
+++ b/extensions/wikidata/module/scripts/dialogs/manage-account-dialog.js
@@ -1,8 +1,29 @@
var ManageAccountDialog = {};
+/*
+ $.post(
+ "command/core/get-all-preferences",
+ null,
+ populatePreferences,
+ "json"
+ );
+*/
+
ManageAccountDialog.launch = function(logged_in_username, callback) {
+ $.post(
+ "command/core/get-all-preferences",
+ null,
+ function (preferences) {
+ ManageAccountDialog.display(logged_in_username, preferences.wikidata_credentials, callback);
+ },
+ "json"
+ );
+};
+
+ManageAccountDialog.display = function(logged_in_username, saved_credentials, callback) {
var self = this;
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/manage-account-dialog.html"));
var elmts = this._elmts = DOM.bind(frame);
+ console.log(saved_credentials);
this._level = DialogSystem.showDialog(frame);
diff --git a/extensions/wikidata/src/org/openrefine/wikidata/commands/LoginCommand.java b/extensions/wikidata/src/org/openrefine/wikidata/commands/LoginCommand.java
index 83ccea2a1..50b68e0c8 100644
--- a/extensions/wikidata/src/org/openrefine/wikidata/commands/LoginCommand.java
+++ b/extensions/wikidata/src/org/openrefine/wikidata/commands/LoginCommand.java
@@ -12,7 +12,8 @@ import org.json.JSONWriter;
import org.openrefine.wikidata.editing.ConnectionManager;
import com.google.refine.commands.Command;
-
+import com.google.refine.preference.PreferenceStore;
+import com.google.refine.ProjectManager;
public class LoginCommand extends Command {
@Override
@@ -20,9 +21,11 @@ public class LoginCommand extends Command {
throws ServletException, IOException {
String username = request.getParameter("wb-username");
String password = request.getParameter("wb-password");
+ String remember = request.getParameter("remember-credentials");
+ System.out.println(remember);
ConnectionManager manager = ConnectionManager.getInstance();
if (username != null && password != null) {
- manager.login(username, password);
+ manager.login(username, password, "on".equals(remember));
} else if ("true".equals(request.getParameter("logout"))) {
manager.logout();
}
diff --git a/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java b/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java
index 51b638882..46a6c83ec 100644
--- a/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java
+++ b/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java
@@ -48,17 +48,21 @@ public class ConnectionManager {
connection = null;
}
- public void login(String username, String password) {
- try {
- JSONArray array = new JSONArray();
- JSONObject obj = new JSONObject();
- obj.put("username", username);
- obj.put("password", password);
- array.put(obj);
- prefStore.put(PREFERENCE_STORE_KEY, array);
- } catch (JSONException e) {
- e.printStackTrace();
+ public void login(String username, String password, boolean rememberCredentials) {
+ if (rememberCredentials) {
+ try {
+ JSONArray array = new JSONArray();
+ JSONObject obj = new JSONObject();
+ obj.put("username", username);
+ obj.put("password", password);
+ array.put(obj);
+ prefStore.put(PREFERENCE_STORE_KEY, array);
+ // TODO save preferences (find out how)
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
}
+
connection = ApiConnection.getWikidataApiConnection();
try {
connection.login(username, password);
@@ -67,19 +71,17 @@ public class ConnectionManager {
}
}
- public void restorePreviousLogin() {
+ public JSONObject getStoredCredentials() {
JSONArray array = (JSONArray) prefStore.get(PREFERENCE_STORE_KEY);
if (array.length() > 0) {
JSONObject obj;
try {
- obj = array.getJSONObject(0);
- String username = obj.getString("username");
- String password = obj.getString("password");
- login(username, password);
+ return array.getJSONObject(0);
} catch (JSONException e) {
e.printStackTrace();
}
}
+ return null;
}
public void logout() {