Start storing user credentials in OpenRefine's preferences
This commit is contained in:
parent
7a6e4f49b1
commit
5faa432aa6
@ -3,7 +3,6 @@
|
|||||||
<div class="dialog-body" bind="dialogBody">
|
<div class="dialog-body" bind="dialogBody">
|
||||||
<p class="body-text">
|
<p class="body-text">
|
||||||
Logging in to Wikidata will allow you to perform edits directly from OpenRefine.
|
Logging in to Wikidata will allow you to perform edits directly from OpenRefine.
|
||||||
Your credentials will be stored unencrypted in OpenRefine's preferences.
|
|
||||||
</p>
|
</p>
|
||||||
<div class="wikibase-user-management-area">
|
<div class="wikibase-user-management-area">
|
||||||
<div class="wikibase-user-login" bind="loginArea">
|
<div class="wikibase-user-login" bind="loginArea">
|
||||||
@ -18,6 +17,10 @@
|
|||||||
<td><label for="wb-password">Password:</label></td>
|
<td><label for="wb-password">Password:</label></td>
|
||||||
<td><input name="wb-password" type="password" placeholder="Enter your password" /></td>
|
<td><input name="wb-password" type="password" placeholder="Enter your password" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><input type="checkbox" name="remember-credentials" /></td>
|
||||||
|
<td><label for="remember-credentials">Remember credentials (stored unencrypted in OpenRefine's preferences)</label></td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
<div class="wikibase-login-buttons">
|
<div class="wikibase-login-buttons">
|
||||||
|
@ -1,8 +1,29 @@
|
|||||||
var ManageAccountDialog = {};
|
var ManageAccountDialog = {};
|
||||||
|
/*
|
||||||
|
$.post(
|
||||||
|
"command/core/get-all-preferences",
|
||||||
|
null,
|
||||||
|
populatePreferences,
|
||||||
|
"json"
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
ManageAccountDialog.launch = function(logged_in_username, callback) {
|
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 self = this;
|
||||||
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/manage-account-dialog.html"));
|
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/manage-account-dialog.html"));
|
||||||
var elmts = this._elmts = DOM.bind(frame);
|
var elmts = this._elmts = DOM.bind(frame);
|
||||||
|
console.log(saved_credentials);
|
||||||
|
|
||||||
this._level = DialogSystem.showDialog(frame);
|
this._level = DialogSystem.showDialog(frame);
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ import org.json.JSONWriter;
|
|||||||
import org.openrefine.wikidata.editing.ConnectionManager;
|
import org.openrefine.wikidata.editing.ConnectionManager;
|
||||||
|
|
||||||
import com.google.refine.commands.Command;
|
import com.google.refine.commands.Command;
|
||||||
|
import com.google.refine.preference.PreferenceStore;
|
||||||
|
import com.google.refine.ProjectManager;
|
||||||
|
|
||||||
public class LoginCommand extends Command {
|
public class LoginCommand extends Command {
|
||||||
@Override
|
@Override
|
||||||
@ -20,9 +21,11 @@ public class LoginCommand extends Command {
|
|||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
String username = request.getParameter("wb-username");
|
String username = request.getParameter("wb-username");
|
||||||
String password = request.getParameter("wb-password");
|
String password = request.getParameter("wb-password");
|
||||||
|
String remember = request.getParameter("remember-credentials");
|
||||||
|
System.out.println(remember);
|
||||||
ConnectionManager manager = ConnectionManager.getInstance();
|
ConnectionManager manager = ConnectionManager.getInstance();
|
||||||
if (username != null && password != null) {
|
if (username != null && password != null) {
|
||||||
manager.login(username, password);
|
manager.login(username, password, "on".equals(remember));
|
||||||
} else if ("true".equals(request.getParameter("logout"))) {
|
} else if ("true".equals(request.getParameter("logout"))) {
|
||||||
manager.logout();
|
manager.logout();
|
||||||
}
|
}
|
||||||
|
@ -48,17 +48,21 @@ public class ConnectionManager {
|
|||||||
connection = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void login(String username, String password) {
|
public void login(String username, String password, boolean rememberCredentials) {
|
||||||
try {
|
if (rememberCredentials) {
|
||||||
JSONArray array = new JSONArray();
|
try {
|
||||||
JSONObject obj = new JSONObject();
|
JSONArray array = new JSONArray();
|
||||||
obj.put("username", username);
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("password", password);
|
obj.put("username", username);
|
||||||
array.put(obj);
|
obj.put("password", password);
|
||||||
prefStore.put(PREFERENCE_STORE_KEY, array);
|
array.put(obj);
|
||||||
} catch (JSONException e) {
|
prefStore.put(PREFERENCE_STORE_KEY, array);
|
||||||
e.printStackTrace();
|
// TODO save preferences (find out how)
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = ApiConnection.getWikidataApiConnection();
|
connection = ApiConnection.getWikidataApiConnection();
|
||||||
try {
|
try {
|
||||||
connection.login(username, password);
|
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);
|
JSONArray array = (JSONArray) prefStore.get(PREFERENCE_STORE_KEY);
|
||||||
if (array.length() > 0) {
|
if (array.length() > 0) {
|
||||||
JSONObject obj;
|
JSONObject obj;
|
||||||
try {
|
try {
|
||||||
obj = array.getJSONObject(0);
|
return array.getJSONObject(0);
|
||||||
String username = obj.getString("username");
|
|
||||||
String password = obj.getString("password");
|
|
||||||
login(username, password);
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logout() {
|
public void logout() {
|
||||||
|
Loading…
Reference in New Issue
Block a user