Advertisement
Guest User

Untitled

a guest
Jul 29th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1.  
  2. @FXML
  3. private void createAccountButtonClicked() { // Create Admin Account on first-time app use.
  4. login_icon.setVisible(false); // Blue "Person" Icon Badge.
  5. if(!new_username_text_field.getText().isEmpty() && !password_text_field.getText().isEmpty() && !new_username_text_field.getText().contains(" ") && new_username_text_field.getText().length() >= 6 && !password_text_field.getText().contains(" ") && password_text_field.getText().length() >= 6) {
  6. Airport.writeToDb("login.db", "INSERT INTO LoginAccounts (Username, Password, `Admin Privileges`) VALUES('" + new_username_text_field.getText() + "', '" + password_text_field.getText() + "', 'YES')"); // YES is to mean it is an Admin.
  7. incorrect_login_icon.setVisible(false); // If admin fails and then successfully creates the initial account.
  8. button_createAccount.setStyle("-fx-background-color: #8BC34A; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
  9. new_username_text_field.setStyle(username_combo_box.getStyle() + " -fx-prompt-text-fill: #000000;");
  10. password_text_field.setStyle(password_text_field.getStyle() + " -fx-prompt-text-fill: #000000;");
  11. correct_login_icon.setVisible(true);
  12. FadeTransition admin_paneFadeIn = new FadeTransition(Duration.millis(1000), post_login_pane); // Fades In Admin Panel
  13. admin_paneFadeIn.setFromValue(0);
  14. admin_paneFadeIn.setToValue(1);
  15. admin_paneFadeIn.play();
  16. post_login_pane.setDisable(false);
  17. split_pane.setDisable(false);
  18. split_pane.setVisible(true);
  19. split_pane.setDividerPositions(0.2);
  20. admin_notification_pane.setDisable(false);
  21. admin_notification_pane.setVisible(true);
  22. notification = new JFXSnackbar();
  23. notification.registerSnackbarContainer(main_pane);
  24. notification.getStyleClass().add("GREEN");
  25. notification.show("Welcome!", 3000);
  26. }
  27. else {
  28. incorrect_login_icon.setVisible(true);
  29. button_createAccount.setStyle("-fx-background-color: #E81123; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
  30. new_username_text_field.setStyle(username_combo_box.getStyle() + " -fx-prompt-text-fill: #E81123;");
  31. password_text_field.setStyle(password_text_field.getStyle() + " -fx-prompt-text-fill: #E81123;");
  32. notification = new JFXSnackbar();
  33. notification.registerSnackbarContainer(main_pane);
  34. notification.show("No Spaces, Minimum 6 characters!", 3000);
  35. }
  36. }
  37. @FXML
  38. private void enter_key_to_loginPressed(KeyEvent event) { // Press enter to login. (only if username or password field is focused).
  39. if(!button_createAccount.isDisabled() && post_login_pane.isDisabled() && event.getCode().equals(KeyCode.ENTER)) // Making sure it only catches Enter key and BEFORE the post login pane is showed.
  40. createAccountButtonClicked(); // Calls all the behaviours that create account button has.
  41. else if(button_createAccount.isDisabled() && post_login_pane.isDisabled() && event.getCode().equals(KeyCode.ENTER))
  42. login_buttonClicked(); // Calls all the behaviours that login button has (login check).
  43. }
  44. @FXML
  45. private void login_buttonClicked() { // Login Check.
  46. ObservableList<ObservableList> dbPassword = Airport.readFromDb("login.db", "SELECT Password FROM LoginAccounts WHERE Username='" + username_combo_box.getValue() + "';");
  47. ObservableList<ObservableList> isAdmin = Airport.readFromDb("login.db", "SELECT `Admin Privileges` FROM LoginAccounts WHERE Username='" + username_combo_box.getValue() + "';");
  48. login_icon.setVisible(false);
  49. if(dbPassword.get(0).contains(password_text_field.getText())) {
  50. login_button.setPrefWidth(75);
  51. login_button.setText("Logged in!");
  52. login_button.setStyle("-fx-background-color: #8BC34A; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
  53. incorrect_login_icon.setVisible(false);
  54. correct_login_icon.setVisible(true);
  55. FadeTransition admin_paneFadeIn = new FadeTransition(Duration.millis(1000), post_login_pane);
  56. admin_paneFadeIn.setFromValue(0);
  57. admin_paneFadeIn.setToValue(1);
  58. admin_paneFadeIn.play();
  59. post_login_pane.setDisable(false);
  60. split_pane.setDisable(false);
  61. split_pane.setVisible(true);
  62. split_pane.setDividerPositions(0.2);
  63. if(isAdmin.get(0).contains("YES")) { // User is Admin.
  64. admin_notification_pane.setDisable(false);
  65. admin_notification_pane.setVisible(true);
  66. notification = new JFXSnackbar();
  67. notification.registerSnackbarContainer(main_pane);
  68. notification.getStyleClass().add("GREEN");
  69. notification.show("Welcome back, " + Arrays.asList(Airport.readFromDb("login.db", "SELECT Username FROM LoginAccounts").get(0).toString().replaceAll("[\\[\\]\\s+]", "").split(",")).get(0) + "!", 3000);
  70. }
  71. else { // User is secretary.
  72. secretary_notification_pane.setDisable(false);
  73. secretary_notification_pane.setVisible(true);
  74. add_plane_button.setDisable(true); // Because of no permissions.
  75. edit_plane_button.setDisable(true);
  76. delete_plane_button.setDisable(true);
  77. add_flight_button.setDisable(true); // -||-
  78. edit_flight_button.setDisable(true);
  79. delete_flight_button.setDisable(true);
  80. add_pilot_button.setDisable(true); // -||-
  81. edit_pilot_button.setDisable(true);
  82. delete_pilot_button.setDisable(true);
  83. secretaries_button.setDisable(true);
  84. secretaries_button.setVisible(false);
  85. accounts_button.setDisable(true);
  86. accounts_button.setVisible(false);
  87. logout_button.setTranslateY(-44); // To move the button 44 pixels up (where the secretaries' one was).
  88. left_navigation_pane.setTranslateY(14); // Some cosmetics.
  89. }
  90. }
  91. else {
  92. password_text_field.setText("");
  93. password_text_field.setPromptText("Incorrect Password!");
  94. login_button.setStyle("-fx-background-color: #E81123; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
  95. incorrect_login_icon.setVisible(true);
  96. }
  97. }
  98. @FXML
  99. private void logout_buttonClicked(ActionEvent event) throws Exception {
  100. ((Stage)((JFXButton)event.getSource()).getScene().getWindow()).close(); // Closes the current session.
  101. Airport app = new Airport(); // Creates an Main object (Airport) so we can call its non-static method bellow (start).
  102. Stage stage = new Stage(); // Creates a new stage (session).
  103. app.start(stage); // Starts it.
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement