Merge pull request #1471 from menocar/password-reconnect

Fix the issue that on reconnect client didn't send password.
This commit is contained in:
LevelX2 2016-01-14 10:10:43 +01:00
commit 9afc4ba2e2
4 changed files with 68 additions and 16 deletions

View file

@ -745,9 +745,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
}
private boolean performConnect() {
String userName = prefs.get("userName", "");
// 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"));
@ -757,6 +761,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
Connection connection = new Connection();
connection.setUsername(userName);
connection.setPassword(password);
connection.setHost(server);
connection.setPort(port);
connection.setProxyType(proxyType);

View file

@ -97,18 +97,22 @@ public class ConnectDialog extends MageDialog {
this.txtUserName.addActionListener(connectAction);
this.txtPassword.addActionListener(connectAction);
registerUserDialog = new RegisterUserDialog();
registerUserDialog = new RegisterUserDialog(this);
MageFrame.getDesktop().add(registerUserDialog, JLayeredPane.POPUP_LAYER);
resetPasswordDialog = new ResetPasswordDialog();
resetPasswordDialog = new ResetPasswordDialog(this);
MageFrame.getDesktop().add(resetPasswordDialog, JLayeredPane.POPUP_LAYER);
}
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.");
}
@ -587,6 +599,14 @@ public class ConnectDialog extends MageDialog {
resetPasswordDialog.showDialog();
}//GEN-LAST:event_btnForgotPasswordActionPerformed
public String getServer() {
return this.txtServer.getText();
}
public String getPort() {
return this.txtPort.getText();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnConnect;

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;
@ -15,6 +16,7 @@ import org.apache.log4j.Logger;
public class RegisterUserDialog extends MageDialog {
private static final Logger logger = Logger.getLogger(ConnectDialog.class);
private ConnectDialog connectDialog;
private Connection connection;
private ConnectTask task;
private Session session;
@ -22,13 +24,14 @@ public class RegisterUserDialog extends MageDialog {
/**
* Creates new form RegisterUserDialog
*/
public RegisterUserDialog() {
public RegisterUserDialog(ConnectDialog connectDialog) {
initComponents();
this.connectDialog = connectDialog;
}
public void showDialog() {
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
this.txtServer.setText(this.connectDialog.getServer());
this.txtPort.setText(this.connectDialog.getPort());
this.lblStatus.setText("");
this.setModal(true);
@ -236,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;
@ -15,6 +16,7 @@ import org.apache.log4j.Logger;
public class ResetPasswordDialog extends MageDialog {
private static final Logger logger = Logger.getLogger(ResetPasswordDialog.class);
private ConnectDialog connectDialog;
private Connection connection;
private Session session;
private GetAuthTokenTask getAuthTokenTask;
@ -23,13 +25,16 @@ public class ResetPasswordDialog extends MageDialog {
/**
* Creates new form ResetPasswordDialog
*/
public ResetPasswordDialog() {
public ResetPasswordDialog(ConnectDialog connectDialog) {
initComponents();
this.connectDialog = connectDialog;
}
public void showDialog() {
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
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);
@ -334,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);
@ -376,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 {