Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package controllers;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Button;
- import javafx.scene.control.TextField;
- import service.UserService;
- public class LogInController {
- @FXML
- public TextField userText;
- @FXML
- public TextField passText;
- @FXML
- public Button logInBtn;
- private UserService usrServ;
- /**
- * Constructor with no parameters
- */
- public LogInController(){
- }
- @FXML
- public void initialize(){
- }
- /**
- * Function to set the service for logInController
- * @param srv - UserService object
- */
- public void setService(UserService srv){
- this.usrServ = srv;
- }
- /**
- * Function to handle logIn action
- * @param actionEvent - action Event object
- */
- public void handleLogIn(ActionEvent actionEvent) {
- String userName = userText.getText();
- String pass = passText.getText();
- boolean logInSuccess = validateLogInController(userName, pass);
- if(!logInSuccess){
- showInfoMessage("Incorrect credentials!","Incorrect username or password, please try again :)");
- return;
- }
- else{
- showInfoMessage("Correct credentials!", "Successfully connected!");
- }
- }
- /**
- * Function to show info prompts to the user
- * @param text - string to show
- * @param title - title string
- */
- private void showInfoMessage(String title, String text) {
- Alert msg = new Alert(Alert.AlertType.INFORMATION);
- msg.setTitle(title);
- msg.setContentText(text);
- msg.showAndWait();
- }
- /**
- * Function to check if the user is in the database
- * @param userName - username
- * @param pass - password
- */
- private boolean validateLogInController(String userName, String pass) {
- return usrServ.validateLogIn(userName, pass);
- }
- /**
- * Function for closing the logIn windows
- */
- public void close() {
- }
- }
Add Comment
Please, Sign In to add comment