Added LoginDialog
This commit is contained in:
@ -71,15 +71,13 @@ public class Startup {
|
||||
EnvoyLog.setFileLevelBarrier(config.getFileLevelBarrier());
|
||||
EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier());
|
||||
|
||||
// Ask the user for their user name
|
||||
String userName = JOptionPane.showInputDialog("Please enter your username");
|
||||
if (userName == null || userName.isEmpty()) {
|
||||
logger.severe("User name is not set or empty. Exiting...");
|
||||
System.exit(1);
|
||||
}
|
||||
// Ask the user for their user name and password
|
||||
LoginCredentials credentials = new LoginDialog().getCredentials();
|
||||
|
||||
// TODO: create dialog
|
||||
String pass = JOptionPane.showInputDialog("Enter password");
|
||||
if (credentials == null) {
|
||||
logger.info("The login process has been aborted by the user. Exiting...");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// Initialize the local database
|
||||
LocalDB localDB;
|
||||
@ -99,18 +97,18 @@ public class Startup {
|
||||
Client client = new Client();
|
||||
try {
|
||||
// Try entering online mode first
|
||||
client.onlineInit(new LoginCredentials(userName, pass.toCharArray()));
|
||||
client.onlineInit(credentials);
|
||||
} catch (Exception e1) {
|
||||
logger.warning("Could not connect to server. Trying offline mode...");
|
||||
e1.printStackTrace();
|
||||
try {
|
||||
// Try entering offline mode
|
||||
localDB.loadUsers();
|
||||
User clientUser = localDB.getUsers().get(userName);
|
||||
User clientUser = localDB.getUsers().get(credentials.getName());
|
||||
if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown");
|
||||
client.setSender(clientUser);
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"A connection to the server could not be established. Starting in offline mode.",
|
||||
"A connection to the server could not be established. Starting in offline mode.\n" + e1,
|
||||
"Connection error",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
} catch (Exception e2) {
|
||||
@ -132,7 +130,7 @@ public class Startup {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Error while loading local database: " + e.toString() + "\nChats might not be stored locally.",
|
||||
"Error while loading local database: " + e + "\nChats might not be stored locally.",
|
||||
"Local DB error",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user