First commit

This commit is contained in:
Alessandro Ferro
2023-07-22 10:44:36 +02:00
parent b3ad4a0882
commit dde958babd
58 changed files with 3723 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package controllers;
import java.net.InetAddress;
import java.net.UnknownHostException;
import code.SshEngine;
import code.GuiAbstractions.Implementations.JFrameFactory;
import code.GuiAbstractions.Interfaces.IFrameFactory;
import views.interfaces.ILoginFrame;
public class LoginController {
private ILoginFrame frame;
public LoginController() {
try {
frame = (ILoginFrame) JFrameFactory.createJFrame(IFrameFactory.LOGIN, this);
}
catch (Exception e) {
e.printStackTrace();
}
}
public boolean Login(String host, String username, String password, String port) throws IllegalArgumentException {
LoginCredentials.host = host;
LoginCredentials.username = username;
LoginCredentials.password = password;
LoginCredentials.port = Integer.parseInt(port);
if (SshEngine.connetion()) {
frame.setVisible(false);
new DesktopController().showFrame(true);;
return true;
}
else {
return false;
}
}
public void ValidateInput(String host, String username, String password, String port) throws IllegalArgumentException {
// Host Validation. Consider its necessity.
try {
InetAddress.getByName(host);
} catch (UnknownHostException ex) {
throw new IllegalArgumentException("Host could not be found", ex);
}
// Port Validation
try {
Integer.parseInt(port);
}
catch(NumberFormatException ex) {
throw new IllegalArgumentException("Invalid port number", ex);
}
}
public void showFrame(boolean show) {
frame.setVisible(show);
}
public static class LoginCredentials{
public static String host;
public static String username;
public static String password;
public static int port;
}
}