Store usrName and password per server. Update input boxes with corresponding values when server is changed in ConnectDialog. Save prefs on successful requests in RegisterUserDialog and ResetPasswordDialog.

This commit is contained in:
Me Car 2016-01-14 18:00:04 +09:00
parent f5765383c7
commit b114c17135
4 changed files with 48 additions and 10 deletions

View file

@ -745,10 +745,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}
private boolean performConnect() {
String userName = prefs.get("userName", "");
String password = prefs.get("password", "");
// TODO: Create MagePreference class to consolidate duplicated preference code in
// MageFrame, ConnectDialog and PreferencesDialog.
String server = prefs.get("serverAddress", "");
int port = Integer.parseInt(prefs.get("serverPort", ""));
// For userName and password we save preference per server.
String userName = prefs.get(server + "/userName", "");
String password = prefs.get(server + "/password", "");
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
ProxyType proxyType = ProxyType.valueByText(prefs.get("proxyType", "None"));

View file

@ -105,10 +105,14 @@ public class ConnectDialog extends MageDialog {
}
public void showDialog() {
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
// TODO: Create MagePreference class to consolidate duplicated preference code in
// MageFrame, ConnectDialog and PreferencesDialog.
String serverAddress = MageFrame.getPreferences().get("serverAddress", Config.serverName);
this.txtServer.setText(serverAddress);
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
this.txtUserName.setText(MageFrame.getPreferences().get("userName", ""));
this.txtPassword.setText(MageFrame.getPreferences().get("password", ""));
// For userName and password we save preference per server.
this.txtUserName.setText(MageFrame.getPreferences().get(serverAddress + "/userName", ""));
this.txtPassword.setText(MageFrame.getPreferences().get(serverAddress + "/password", ""));
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get(KEY_CONNECT_AUTO_CONNECT, "false")));
this.chkForceUpdateDB.setSelected(false); // has always to be set manually to force comparison
@ -127,10 +131,14 @@ public class ConnectDialog extends MageDialog {
}
private void saveSettings() {
MageFrame.getPreferences().put("serverAddress", txtServer.getText().trim());
// TODO: Create MagePreference class to consolidate duplicated preference code in
// MageFrame, ConnectDialog and PreferencesDialog.
String serverAddress = txtServer.getText().trim();
MageFrame.getPreferences().put("serverAddress", serverAddress);
MageFrame.getPreferences().put("serverPort", txtPort.getText().trim());
MageFrame.getPreferences().put("userName", txtUserName.getText().trim());
MageFrame.getPreferences().put("password", txtPassword.getText().trim());
// For userName and password we save preference per server.
MageFrame.getPreferences().put(serverAddress + "/userName", txtUserName.getText().trim());
MageFrame.getPreferences().put(serverAddress + "/password", txtPassword.getText().trim());
MageFrame.getPreferences().put(KEY_CONNECT_AUTO_CONNECT, Boolean.toString(chkAutoConnect.isSelected()));
}
@ -544,8 +552,12 @@ public class ConnectDialog extends MageDialog {
if (selectedServer != null) {
String[] params = selectedServer.split(":");
if (params.length == 3) {
this.txtServer.setText(params[1]);
String serverAddress = params[1];
this.txtServer.setText(serverAddress);
this.txtPort.setText(params[2]);
// Update userName and password according to the chosen server.
this.txtUserName.setText(MageFrame.getPreferences().get(serverAddress + "/userName", ""));
this.txtPassword.setText(MageFrame.getPreferences().get(serverAddress + "/password", ""));
} else {
JOptionPane.showMessageDialog(null, "Wrong server data format.");
}

View file

@ -4,6 +4,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.prefs.Preferences;
import javax.swing.SwingWorker;
import mage.client.MageFrame;
import mage.client.util.Config;
@ -238,6 +239,16 @@ public class RegisterUserDialog extends MageDialog {
if (result) {
String message = "Registration succeeded";
lblStatus.setText(message);
// Save settings.
Preferences prefs = MageFrame.getPreferences();
prefs.put("serverAddress", connection.getHost());
prefs.put("serverPort", Integer.toString(connection.getPort()));
// For userName and password we save preference per server.
prefs.put(connection.getHost() + "/userName", connection.getUsername());
prefs.put(connection.getHost() + "/password", connection.getPassword());
prefs.put(connection.getHost() + "/email", connection.getEmail());
MageFrame.getInstance().showMessage(message);
hideDialog();
} else {

View file

@ -4,6 +4,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.prefs.Preferences;
import javax.swing.SwingWorker;
import mage.client.MageFrame;
import mage.client.util.Config;
@ -30,8 +31,10 @@ public class ResetPasswordDialog extends MageDialog {
}
public void showDialog() {
this.txtServer.setText(this.connectDialog.getServer());
String serverAddress = this.connectDialog.getServer();
this.txtServer.setText(serverAddress);
this.txtPort.setText(this.connectDialog.getPort());
this.txtEmail.setText(MageFrame.getPreferences().get(serverAddress + "/email", ""));
this.lblStatus.setText("");
this.setModal(true);
@ -336,6 +339,10 @@ public class ResetPasswordDialog extends MageDialog {
try {
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
if (result) {
// Save settings.
Preferences prefs = MageFrame.getPreferences();
prefs.put(connection.getHost() + "/email", connection.getEmail());
String message = "Auth token is emailed. Please check your inbox.";
lblStatus.setText(message);
MageFrame.getInstance().showMessage(message);
@ -378,6 +385,11 @@ public class ResetPasswordDialog extends MageDialog {
if (result) {
String message = "Password is reset successfully.";
lblStatus.setText(message);
// Save settings.
Preferences prefs = MageFrame.getPreferences();
prefs.put(connection.getHost() + "/password", connection.getPassword());
MageFrame.getInstance().showMessage(message);
hideDialog();
} else {