mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 19:11:59 -08:00
Merge pull request #1471 from menocar/password-reconnect
Fix the issue that on reconnect client didn't send password.
This commit is contained in:
commit
9afc4ba2e2
4 changed files with 68 additions and 16 deletions
|
|
@ -745,9 +745,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean performConnect() {
|
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", "");
|
String server = prefs.get("serverAddress", "");
|
||||||
int port = Integer.parseInt(prefs.get("serverPort", ""));
|
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", "");
|
String proxyServer = prefs.get("proxyAddress", "");
|
||||||
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
|
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
|
||||||
ProxyType proxyType = ProxyType.valueByText(prefs.get("proxyType", "None"));
|
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));
|
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||||
Connection connection = new Connection();
|
Connection connection = new Connection();
|
||||||
connection.setUsername(userName);
|
connection.setUsername(userName);
|
||||||
|
connection.setPassword(password);
|
||||||
connection.setHost(server);
|
connection.setHost(server);
|
||||||
connection.setPort(port);
|
connection.setPort(port);
|
||||||
connection.setProxyType(proxyType);
|
connection.setProxyType(proxyType);
|
||||||
|
|
|
||||||
|
|
@ -97,18 +97,22 @@ public class ConnectDialog extends MageDialog {
|
||||||
this.txtUserName.addActionListener(connectAction);
|
this.txtUserName.addActionListener(connectAction);
|
||||||
this.txtPassword.addActionListener(connectAction);
|
this.txtPassword.addActionListener(connectAction);
|
||||||
|
|
||||||
registerUserDialog = new RegisterUserDialog();
|
registerUserDialog = new RegisterUserDialog(this);
|
||||||
MageFrame.getDesktop().add(registerUserDialog, JLayeredPane.POPUP_LAYER);
|
MageFrame.getDesktop().add(registerUserDialog, JLayeredPane.POPUP_LAYER);
|
||||||
|
|
||||||
resetPasswordDialog = new ResetPasswordDialog();
|
resetPasswordDialog = new ResetPasswordDialog(this);
|
||||||
MageFrame.getDesktop().add(resetPasswordDialog, JLayeredPane.POPUP_LAYER);
|
MageFrame.getDesktop().add(resetPasswordDialog, JLayeredPane.POPUP_LAYER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog() {
|
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.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
||||||
this.txtUserName.setText(MageFrame.getPreferences().get("userName", ""));
|
// For userName and password we save preference per server.
|
||||||
this.txtPassword.setText(MageFrame.getPreferences().get("password", ""));
|
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.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
|
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() {
|
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("serverPort", txtPort.getText().trim());
|
||||||
MageFrame.getPreferences().put("userName", txtUserName.getText().trim());
|
// For userName and password we save preference per server.
|
||||||
MageFrame.getPreferences().put("password", txtPassword.getText().trim());
|
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()));
|
MageFrame.getPreferences().put(KEY_CONNECT_AUTO_CONNECT, Boolean.toString(chkAutoConnect.isSelected()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -544,8 +552,12 @@ public class ConnectDialog extends MageDialog {
|
||||||
if (selectedServer != null) {
|
if (selectedServer != null) {
|
||||||
String[] params = selectedServer.split(":");
|
String[] params = selectedServer.split(":");
|
||||||
if (params.length == 3) {
|
if (params.length == 3) {
|
||||||
this.txtServer.setText(params[1]);
|
String serverAddress = params[1];
|
||||||
|
this.txtServer.setText(serverAddress);
|
||||||
this.txtPort.setText(params[2]);
|
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 {
|
} else {
|
||||||
JOptionPane.showMessageDialog(null, "Wrong server data format.");
|
JOptionPane.showMessageDialog(null, "Wrong server data format.");
|
||||||
}
|
}
|
||||||
|
|
@ -587,6 +599,14 @@ public class ConnectDialog extends MageDialog {
|
||||||
resetPasswordDialog.showDialog();
|
resetPasswordDialog.showDialog();
|
||||||
}//GEN-LAST:event_btnForgotPasswordActionPerformed
|
}//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
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JButton btnCancel;
|
private javax.swing.JButton btnCancel;
|
||||||
private javax.swing.JButton btnConnect;
|
private javax.swing.JButton btnConnect;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.util.Config;
|
import mage.client.util.Config;
|
||||||
|
|
@ -15,6 +16,7 @@ import org.apache.log4j.Logger;
|
||||||
public class RegisterUserDialog extends MageDialog {
|
public class RegisterUserDialog extends MageDialog {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ConnectDialog.class);
|
private static final Logger logger = Logger.getLogger(ConnectDialog.class);
|
||||||
|
private ConnectDialog connectDialog;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private ConnectTask task;
|
private ConnectTask task;
|
||||||
private Session session;
|
private Session session;
|
||||||
|
|
@ -22,13 +24,14 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
/**
|
/**
|
||||||
* Creates new form RegisterUserDialog
|
* Creates new form RegisterUserDialog
|
||||||
*/
|
*/
|
||||||
public RegisterUserDialog() {
|
public RegisterUserDialog(ConnectDialog connectDialog) {
|
||||||
initComponents();
|
initComponents();
|
||||||
|
this.connectDialog = connectDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog() {
|
public void showDialog() {
|
||||||
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
|
this.txtServer.setText(this.connectDialog.getServer());
|
||||||
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
this.txtPort.setText(this.connectDialog.getPort());
|
||||||
this.lblStatus.setText("");
|
this.lblStatus.setText("");
|
||||||
|
|
||||||
this.setModal(true);
|
this.setModal(true);
|
||||||
|
|
@ -236,6 +239,16 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
if (result) {
|
if (result) {
|
||||||
String message = "Registration succeeded";
|
String message = "Registration succeeded";
|
||||||
lblStatus.setText(message);
|
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);
|
MageFrame.getInstance().showMessage(message);
|
||||||
hideDialog();
|
hideDialog();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.util.Config;
|
import mage.client.util.Config;
|
||||||
|
|
@ -15,6 +16,7 @@ import org.apache.log4j.Logger;
|
||||||
public class ResetPasswordDialog extends MageDialog {
|
public class ResetPasswordDialog extends MageDialog {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ResetPasswordDialog.class);
|
private static final Logger logger = Logger.getLogger(ResetPasswordDialog.class);
|
||||||
|
private ConnectDialog connectDialog;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private Session session;
|
private Session session;
|
||||||
private GetAuthTokenTask getAuthTokenTask;
|
private GetAuthTokenTask getAuthTokenTask;
|
||||||
|
|
@ -23,13 +25,16 @@ public class ResetPasswordDialog extends MageDialog {
|
||||||
/**
|
/**
|
||||||
* Creates new form ResetPasswordDialog
|
* Creates new form ResetPasswordDialog
|
||||||
*/
|
*/
|
||||||
public ResetPasswordDialog() {
|
public ResetPasswordDialog(ConnectDialog connectDialog) {
|
||||||
initComponents();
|
initComponents();
|
||||||
|
this.connectDialog = connectDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog() {
|
public void showDialog() {
|
||||||
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
|
String serverAddress = this.connectDialog.getServer();
|
||||||
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
this.txtServer.setText(serverAddress);
|
||||||
|
this.txtPort.setText(this.connectDialog.getPort());
|
||||||
|
this.txtEmail.setText(MageFrame.getPreferences().get(serverAddress + "/email", ""));
|
||||||
this.lblStatus.setText("");
|
this.lblStatus.setText("");
|
||||||
|
|
||||||
this.setModal(true);
|
this.setModal(true);
|
||||||
|
|
@ -334,6 +339,10 @@ public class ResetPasswordDialog extends MageDialog {
|
||||||
try {
|
try {
|
||||||
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
if (result) {
|
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.";
|
String message = "Auth token is emailed. Please check your inbox.";
|
||||||
lblStatus.setText(message);
|
lblStatus.setText(message);
|
||||||
MageFrame.getInstance().showMessage(message);
|
MageFrame.getInstance().showMessage(message);
|
||||||
|
|
@ -376,6 +385,11 @@ public class ResetPasswordDialog extends MageDialog {
|
||||||
if (result) {
|
if (result) {
|
||||||
String message = "Password is reset successfully.";
|
String message = "Password is reset successfully.";
|
||||||
lblStatus.setText(message);
|
lblStatus.setText(message);
|
||||||
|
|
||||||
|
// Save settings.
|
||||||
|
Preferences prefs = MageFrame.getPreferences();
|
||||||
|
prefs.put(connection.getHost() + "/password", connection.getPassword());
|
||||||
|
|
||||||
MageFrame.getInstance().showMessage(message);
|
MageFrame.getInstance().showMessage(message);
|
||||||
hideDialog();
|
hideDialog();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue