Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FXML
- private void createAccountButtonClicked() { // Create Admin Account on first-time app use.
- login_icon.setVisible(false); // Blue "Person" Icon Badge.
- 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) {
- 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.
- incorrect_login_icon.setVisible(false); // If admin fails and then successfully creates the initial account.
- button_createAccount.setStyle("-fx-background-color: #8BC34A; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
- new_username_text_field.setStyle(username_combo_box.getStyle() + " -fx-prompt-text-fill: #000000;");
- password_text_field.setStyle(password_text_field.getStyle() + " -fx-prompt-text-fill: #000000;");
- correct_login_icon.setVisible(true);
- FadeTransition admin_paneFadeIn = new FadeTransition(Duration.millis(1000), post_login_pane); // Fades In Admin Panel
- admin_paneFadeIn.setFromValue(0);
- admin_paneFadeIn.setToValue(1);
- admin_paneFadeIn.play();
- post_login_pane.setDisable(false);
- split_pane.setDisable(false);
- split_pane.setVisible(true);
- split_pane.setDividerPositions(0.2);
- admin_notification_pane.setDisable(false);
- admin_notification_pane.setVisible(true);
- notification = new JFXSnackbar();
- notification.registerSnackbarContainer(main_pane);
- notification.getStyleClass().add("GREEN");
- notification.show("Welcome!", 3000);
- }
- else {
- incorrect_login_icon.setVisible(true);
- button_createAccount.setStyle("-fx-background-color: #E81123; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
- new_username_text_field.setStyle(username_combo_box.getStyle() + " -fx-prompt-text-fill: #E81123;");
- password_text_field.setStyle(password_text_field.getStyle() + " -fx-prompt-text-fill: #E81123;");
- notification = new JFXSnackbar();
- notification.registerSnackbarContainer(main_pane);
- notification.show("No Spaces, Minimum 6 characters!", 3000);
- }
- }
- @FXML
- private void enter_key_to_loginPressed(KeyEvent event) { // Press enter to login. (only if username or password field is focused).
- 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.
- createAccountButtonClicked(); // Calls all the behaviours that create account button has.
- else if(button_createAccount.isDisabled() && post_login_pane.isDisabled() && event.getCode().equals(KeyCode.ENTER))
- login_buttonClicked(); // Calls all the behaviours that login button has (login check).
- }
- @FXML
- private void login_buttonClicked() { // Login Check.
- ObservableList<ObservableList> dbPassword = Airport.readFromDb("login.db", "SELECT Password FROM LoginAccounts WHERE Username='" + username_combo_box.getValue() + "';");
- ObservableList<ObservableList> isAdmin = Airport.readFromDb("login.db", "SELECT `Admin Privileges` FROM LoginAccounts WHERE Username='" + username_combo_box.getValue() + "';");
- login_icon.setVisible(false);
- if(dbPassword.get(0).contains(password_text_field.getText())) {
- login_button.setPrefWidth(75);
- login_button.setText("Logged in!");
- login_button.setStyle("-fx-background-color: #8BC34A; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
- incorrect_login_icon.setVisible(false);
- correct_login_icon.setVisible(true);
- FadeTransition admin_paneFadeIn = new FadeTransition(Duration.millis(1000), post_login_pane);
- admin_paneFadeIn.setFromValue(0);
- admin_paneFadeIn.setToValue(1);
- admin_paneFadeIn.play();
- post_login_pane.setDisable(false);
- split_pane.setDisable(false);
- split_pane.setVisible(true);
- split_pane.setDividerPositions(0.2);
- if(isAdmin.get(0).contains("YES")) { // User is Admin.
- admin_notification_pane.setDisable(false);
- admin_notification_pane.setVisible(true);
- notification = new JFXSnackbar();
- notification.registerSnackbarContainer(main_pane);
- notification.getStyleClass().add("GREEN");
- notification.show("Welcome back, " + Arrays.asList(Airport.readFromDb("login.db", "SELECT Username FROM LoginAccounts").get(0).toString().replaceAll("[\\[\\]\\s+]", "").split(",")).get(0) + "!", 3000);
- }
- else { // User is secretary.
- secretary_notification_pane.setDisable(false);
- secretary_notification_pane.setVisible(true);
- add_plane_button.setDisable(true); // Because of no permissions.
- edit_plane_button.setDisable(true);
- delete_plane_button.setDisable(true);
- add_flight_button.setDisable(true); // -||-
- edit_flight_button.setDisable(true);
- delete_flight_button.setDisable(true);
- add_pilot_button.setDisable(true); // -||-
- edit_pilot_button.setDisable(true);
- delete_pilot_button.setDisable(true);
- secretaries_button.setDisable(true);
- secretaries_button.setVisible(false);
- accounts_button.setDisable(true);
- accounts_button.setVisible(false);
- logout_button.setTranslateY(-44); // To move the button 44 pixels up (where the secretaries' one was).
- left_navigation_pane.setTranslateY(14); // Some cosmetics.
- }
- }
- else {
- password_text_field.setText("");
- password_text_field.setPromptText("Incorrect Password!");
- login_button.setStyle("-fx-background-color: #E81123; -fx-text-fill: #f7f7f7; -fx-background-radius: 0;");
- incorrect_login_icon.setVisible(true);
- }
- }
- @FXML
- private void logout_buttonClicked(ActionEvent event) throws Exception {
- ((Stage)((JFXButton)event.getSource()).getScene().getWindow()).close(); // Closes the current session.
- Airport app = new Airport(); // Creates an Main object (Airport) so we can call its non-static method bellow (start).
- Stage stage = new Stage(); // Creates a new stage (session).
- app.start(stage); // Starts it.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement