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">
|
||||
<p class="body-text">
|
||||
Logging in to Wikidata will allow you to perform edits directly from OpenRefine.
|
||||
Your credentials will be stored unencrypted in OpenRefine's preferences.
|
||||
</p>
|
||||
<div class="wikibase-user-management-area">
|
||||
<div class="wikibase-user-login" bind="loginArea">
|
||||
@ -18,6 +17,10 @@
|
||||
<td><label for="wb-password">Password:</label></td>
|
||||
<td><input name="wb-password" type="password" placeholder="Enter your password" /></td>
|
||||
</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>
|
||||
</form>
|
||||
<div class="wikibase-login-buttons">
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ public class ConnectionManager {
|
||||
connection = null;
|
||||
}
|
||||
|
||||
public void login(String username, String password) {
|
||||
public void login(String username, String password, boolean rememberCredentials) {
|
||||
if (rememberCredentials) {
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
JSONObject obj = new JSONObject();
|
||||
@ -56,9 +57,12 @@ public class ConnectionManager {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user