I successfully logged a user in, however, when I save the userID in userLogin(Profile dto) which is in ProfileDataAccessObject.java. I can't seem to access the userID in other Controller or DataAccessObject class.
LoginController.java
public class LoginController implements Initializable {
@FXML private TextField username; // where the user enters their username
@FXML private PasswordField password; // where the user enters the password
@FXML private Button loginBtn; // authenticates users details when clicked
@FXML public Label wrongLogin; // label displayed when login is unsuccessful
@FXML private Hyperlink accountRegistrationLink; // when clicked take user to signup
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
}
public void userLogin(ActionEvent actionEvent) {
if (actionEvent.getSource().equals(loginBtn)) {
Connection connection = DatabaseHandlerSingleton.getDatabaseHandlerSingleton();
profile = new Profile(username.getText(), password.getText());
ProfileDataAccessObject profileDataAccessObject = new ProfileDataAccessObject(connection);
if (profileDataAccessObject.login(profile) == null) {
System.out.println("Login failed");
} else {
//change scene to workspace
FactorySceneViewCreator.changeScene(actionEvent, "workspace");
}
}
}
}
WorkspaceController.java
public class WorkspaceController implements Initializable {
private LoginController loginController = new LoginController();
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
System.out.println(loginController.profile.toString());
}
}
Console Output:
Profile{id=0, email='null', username='null', password='null', user=null, session=null, profilePicturePath='null', encryption=null}