iuliaa

Untitled

Jun 18th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.11 KB | None | 0 0
  1. package org.bsa.controllers;
  2.  
  3. import javafx.application.Application;
  4. import javafx.collections.FXCollections;
  5. import javafx.fxml.FXML;
  6. import javafx.fxml.FXMLLoader;
  7. import javafx.scene.Parent;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.*;
  10. import javafx.scene.layout.StackPane;
  11. import javafx.scene.paint.Color;
  12. import javafx.stage.Stage;
  13. import org.bsa.exceptions.InvalidRole;
  14. import org.bsa.exceptions.LoginFail;
  15. import org.bsa.model.User;
  16. import org.bsa.service.AppointmentService;
  17. import org.bsa.service.EmployeeService;
  18. import org.bsa.service.ServicesService;
  19. import org.bsa.service.UserService;
  20. import javafx.scene.control.TextField;
  21.  
  22. import java.io.IOException;
  23.  
  24. import static org.bsa.service.UserService.checkLoginCredentials;
  25.  
  26. //import javax.jws.soap.SOAPBinding;
  27. //import javax.xml.soap.Text;
  28.  
  29. public class LoginController {
  30.     @FXML
  31.     private Button loginButton;
  32.     @FXML
  33.     private TextField usernameTextField;
  34.     @FXML
  35.     private TextField passwordTextField;
  36.     @FXML
  37.     private ChoiceBox userChoiceBox;
  38.     @FXML
  39.     private TextField text;
  40.     @FXML
  41.     private Label warningLogin;
  42.     Stage stage;
  43.     private String u;
  44.     //private UserService U;
  45.  
  46.     @FXML
  47.     public void initialize() throws IOException{
  48.         //EmployeeService.writeEmployees();
  49.         //ServicesService.addServices();
  50.         userChoiceBox.getItems().addAll("Employee", "Customer");
  51.         userChoiceBox.setValue("Customer");
  52.  
  53.     }
  54.  
  55.  
  56.     public void handleLoginAction() throws LoginFail, IOException, InvalidRole {
  57.         User usr= new User();
  58.         String username = usernameTextField.getText();
  59.         String password = passwordTextField.getText();
  60.         String role = (String) userChoiceBox.getValue();
  61.         usr.setUsername(username);
  62.         usr.setPassword(password);
  63.         usr.setRole(role);
  64.         //missing username
  65.         if(username==null || username.isEmpty())
  66.         {
  67.             warningLogin.setText("Please enter your username!");
  68.             return;
  69.         }
  70.  
  71.         //missing password
  72.         if(password==null || password.isEmpty())
  73.         {
  74.             warningLogin.setText("Please enter your password!");
  75.             return;
  76.         }
  77.  
  78.         //check if correct credentials
  79.         try {
  80.             checkLoginCredentials(usr.getUsername(), usr.getPassword(),usr.getRole());
  81.             //log-in as customer
  82.             if(role=="Customer")
  83.             {
  84.                 //go to customer page
  85.                 AppointmentService as=new AppointmentService();
  86.                 as.setClientusr(usr.getUsername());
  87.                 try{
  88.                     Stage stage = (Stage) warningLogin.getScene().getWindow();
  89.                     Parent viewCustomerPageRoot = FXMLLoader.load(getClass().getResource("/CustomerPage.fxml"));
  90.                     Scene customerScene=new Scene(viewCustomerPageRoot,600,380);
  91.                     stage.setScene(customerScene);
  92.                 } catch (IOException e){
  93.                     e.printStackTrace();
  94.                 }
  95.                 return;
  96.             }
  97.  
  98.             //log-in as employee
  99.             if(role=="Employee")
  100.             {
  101.                 //go to employee page
  102.                 ServicesService ss=new ServicesService();
  103.                 AppointmentService aps=new AppointmentService();
  104.                 aps.setUsr(usr.getUsername());
  105.                 ss.setUsr(usr.getUsername());
  106.                 try{
  107.                     Stage stage = (Stage) warningLogin.getScene().getWindow();
  108.                     Parent viewEmployeePageRoot = FXMLLoader.load(getClass().getResource("/EmployeePage.fxml"));
  109.                     Scene employeeScene=new Scene(viewEmployeePageRoot,600,380);
  110.                     stage.setScene(employeeScene);
  111.                 } catch (IOException e){
  112.                     e.printStackTrace();
  113.                 }
  114.                 return;
  115.             }
  116.         }catch (LoginFail e){
  117.             warningLogin.setText("Invalid login! Wrong credentials!");
  118.         }catch (InvalidRole e){
  119.             warningLogin.setText("Invalid login! Wrong role selected!");
  120.         }
  121.  
  122.     }
  123. }
Add Comment
Please, Sign In to add comment