Guest User

Untitled

a guest
Mar 15th, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. package controllers;
  2.  
  3. import javafx.event.ActionEvent;
  4. import javafx.fxml.FXML;
  5. import javafx.scene.control.Alert;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.TextField;
  8. import service.UserService;
  9.  
  10. public class LogInController {
  11.     @FXML
  12.     public TextField userText;
  13.     @FXML
  14.     public TextField passText;
  15.     @FXML
  16.     public Button logInBtn;
  17.  
  18.     private UserService usrServ;
  19.  
  20.     /**
  21.      * Constructor with no parameters
  22.      */
  23.     public LogInController(){
  24.  
  25.     }
  26.  
  27.     @FXML
  28.     public void initialize(){
  29.  
  30.     }
  31.  
  32.     /**
  33.      * Function to set the service for logInController
  34.      * @param srv - UserService object
  35.      */
  36.     public void setService(UserService srv){
  37.         this.usrServ = srv;
  38.     }
  39.  
  40.  
  41.     /**
  42.      * Function to handle logIn action
  43.      * @param actionEvent - action Event object
  44.      */
  45.     public void handleLogIn(ActionEvent actionEvent) {
  46.         String userName = userText.getText();
  47.         String pass = passText.getText();
  48.  
  49.         boolean logInSuccess = validateLogInController(userName, pass);
  50.         if(!logInSuccess){
  51.             showInfoMessage("Incorrect credentials!","Incorrect username or password, please try again :)");
  52.             return;
  53.         }
  54.         else{
  55.             showInfoMessage("Correct credentials!", "Successfully connected!");
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * Function to show info prompts to the user
  61.      * @param text - string to show
  62.      * @param title - title string
  63.      */
  64.     private void showInfoMessage(String title, String text) {
  65.         Alert msg = new Alert(Alert.AlertType.INFORMATION);
  66.         msg.setTitle(title);
  67.         msg.setContentText(text);
  68.         msg.showAndWait();
  69.     }
  70.  
  71.     /**
  72.      * Function to check if the user is in the database
  73.      * @param userName - username
  74.      * @param pass - password
  75.      */
  76.     private boolean validateLogInController(String userName, String pass) {
  77.         return usrServ.validateLogIn(userName, pass);
  78.     }
  79.  
  80.  
  81.     /**
  82.      * Function for closing the logIn windows
  83.      */
  84.     public void close() {
  85.     }
  86.  
  87. }
Add Comment
Please, Sign In to add comment