Skip to content
Snippets Groups Projects
Commit ddeb74e2 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Added notification popup for output parameter sql injection

parent 5a6fbcda
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,8 @@ public class HelpingFunctions { ...@@ -31,6 +31,8 @@ public class HelpingFunctions {
// Number of manual moisture checks // Number of manual moisture checks
public static int NUMBER_OF_CHECKS = 1; public static int NUMBER_OF_CHECKS = 1;
public static int MAX_USER_INPUT_CHARACTERS = 10;
// Today's date // Today's date
public static String CURRENT_DATE = ""; public static String CURRENT_DATE = "";
public static String TIME_LEFT = ""; public static String TIME_LEFT = "";
......
...@@ -16,6 +16,7 @@ import java.util.Map; ...@@ -16,6 +16,7 @@ import java.util.Map;
import static com.application.DB.Constants.*; import static com.application.DB.Constants.*;
import static com.application.DB.DB.getCurrentDrying; import static com.application.DB.DB.getCurrentDrying;
import static com.application.DB.HelpingFunctions.MAX_USER_INPUT_CHARACTERS;
import static com.application.DB.HelpingFunctions.setLoadedData; import static com.application.DB.HelpingFunctions.setLoadedData;
import static com.application.GUI.LineChartFunctionality.*; import static com.application.GUI.LineChartFunctionality.*;
import static com.application.Main.*; import static com.application.Main.*;
...@@ -30,8 +31,6 @@ import static com.application.DB.DB.setInputParameters; ...@@ -30,8 +31,6 @@ import static com.application.DB.DB.setInputParameters;
*/ */
public class InputPopUpWindow { public class InputPopUpWindow {
private static boolean err = false;
public static void display() { public static void display() {
Stage window = new Stage(); Stage window = new Stage();
...@@ -114,7 +113,6 @@ public class InputPopUpWindow { ...@@ -114,7 +113,6 @@ public class InputPopUpWindow {
startButton.setId("inputButtonStart"); startButton.setId("inputButtonStart");
startButton.setOnAction(e -> { startButton.setOnAction(e -> {
// Sets the start time // Sets the start time
HelpingFunctions.CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()); HelpingFunctions.CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
HelpingFunctions.START_TIME = HelpingFunctions.CURRENT_DATE; HelpingFunctions.START_TIME = HelpingFunctions.CURRENT_DATE;
...@@ -129,50 +127,39 @@ public class InputPopUpWindow { ...@@ -129,50 +127,39 @@ public class InputPopUpWindow {
HelpingFunctions.MOISTURE_GOAL = moistureList.getValue(); HelpingFunctions.MOISTURE_GOAL = moistureList.getValue();
} }
boolean err = false;
// If the input is null, sets the value to be empty // If the input is null, sets the value to be empty
if (treeSpeciesList.getValue() == null) { if (treeSpeciesList.getValue() == null) {
HelpingFunctions.TREE_SPECIES = ""; HelpingFunctions.TREE_SPECIES = "";
err = false; } else if (treeSpeciesList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
} else if (treeSpeciesList.getValue().length() > 10) { NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
treeSpeciesList.setValue(""); treeSpeciesList.setValue("");
err = true; err = true;
} else {
err = false;
} }
if (dimensionsList.getValue() == null) { if (dimensionsList.getValue() == null) {
HelpingFunctions.DIMENSIONS = ""; HelpingFunctions.DIMENSIONS = "";
err = false; } else if (dimensionsList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
} else if (dimensionsList.getValue().length() > 10) { NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
dimensionsList.setValue(""); dimensionsList.setValue("");
err = true; err = true;
} else {
err = false;
} }
if (sawsetList.getValue() == null) { if (sawsetList.getValue() == null) {
HelpingFunctions.SAWSET = ""; HelpingFunctions.SAWSET = "";
err = false; } else if (sawsetList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
} else if (sawsetList.getValue().length() > 10) { NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
sawsetList.setValue(""); sawsetList.setValue("");
err = true; err = true;
} else {
err = false;
} }
if (moistureList.getValue() == null) { if (moistureList.getValue() == null) {
HelpingFunctions.MOISTURE_GOAL = ""; HelpingFunctions.MOISTURE_GOAL = "";
err = false; } else if (moistureList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
} else if (moistureList.getValue().length() > 10) { NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
moistureList.setValue(""); moistureList.setValue("");
err = true; err = true;
} else {
err = false;
} }
......
...@@ -15,6 +15,7 @@ import java.time.LocalDateTime; ...@@ -15,6 +15,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import static com.application.DB.HelpingFunctions.IS_FINISHED; import static com.application.DB.HelpingFunctions.IS_FINISHED;
import static com.application.DB.HelpingFunctions.MAX_USER_INPUT_CHARACTERS;
public class OutputPopUpWindow { public class OutputPopUpWindow {
...@@ -30,12 +31,10 @@ public class OutputPopUpWindow { ...@@ -30,12 +31,10 @@ public class OutputPopUpWindow {
moistureCheckLabelHuge.setAlignment(Pos.TOP_CENTER); moistureCheckLabelHuge.setAlignment(Pos.TOP_CENTER);
// Center - Output field // Center - Output field
Label moistureCheckLabelSmall = new Label("Moisture Check:");
moistureCheckLabelSmall.setId("inputLabel");
moistureCheckLabelSmall.setAlignment(Pos.CENTER);
TextField moistureCheckTextField = new TextField(); TextField moistureCheckTextField = new TextField();
moistureCheckTextField.setId("inputLabel"); moistureCheckTextField.setId("inputLabel");
moistureCheckTextField.setAlignment(Pos.CENTER); moistureCheckTextField.setAlignment(Pos.CENTER);
moistureCheckTextField.setPromptText("Please enter a value");
...@@ -45,16 +44,32 @@ public class OutputPopUpWindow { ...@@ -45,16 +44,32 @@ public class OutputPopUpWindow {
countinueButton.setAlignment(Pos.BOTTOM_CENTER); countinueButton.setAlignment(Pos.BOTTOM_CENTER);
countinueButton.setOnAction(e -> { countinueButton.setOnAction(e -> {
try { try {
if(!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) { boolean err = false;
HelpingFunctions.STOP_TIME = null;
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString()); if(moistureCheckTextField.getCharacters().length() > MAX_USER_INPUT_CHARACTERS){
HelpingFunctions.NUMBER_OF_CHECKS++; err = true;
window.close(); }
if(!err){
if(!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) {
HelpingFunctions.STOP_TIME = null;
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
HelpingFunctions.NUMBER_OF_CHECKS++;
window.close();
} else {
NotificationPopUp.displayNotificationWindow("Please enter a value!");
moistureCheckTextField.setPromptText("Please enter a value");
}
} else { } else {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
moistureCheckTextField.setText("");
moistureCheckTextField.setPromptText("Please enter a value"); moistureCheckTextField.setPromptText("Please enter a value");
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
...@@ -64,13 +79,27 @@ public class OutputPopUpWindow { ...@@ -64,13 +79,27 @@ public class OutputPopUpWindow {
finishButton.setAlignment(Pos.BOTTOM_CENTER); finishButton.setAlignment(Pos.BOTTOM_CENTER);
finishButton.setOnAction(e -> { finishButton.setOnAction(e -> {
try { try {
if(!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) { boolean err = false;
IS_FINISHED = true;
HelpingFunctions.STOP_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()); if(moistureCheckTextField.getCharacters().length() > MAX_USER_INPUT_CHARACTERS){
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString()); err = true;
window.close(); }
if(!err) {
if (!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) {
IS_FINISHED = true;
HelpingFunctions.STOP_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
window.close();
} else {
NotificationPopUp.displayNotificationWindow("Please enter a value!");
moistureCheckTextField.setPromptText("Please enter a value");
}
} else { } else {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
moistureCheckTextField.setText("");
moistureCheckTextField.setPromptText("Please enter a value"); moistureCheckTextField.setPromptText("Please enter a value");
} }
} catch (Exception ex) { } catch (Exception ex) {
...@@ -81,7 +110,8 @@ public class OutputPopUpWindow { ...@@ -81,7 +110,8 @@ public class OutputPopUpWindow {
VBox layout = new VBox(10); VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER); layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll(moistureCheckLabelHuge,moistureCheckLabelSmall,moistureCheckTextField,countinueButton,finishButton); layout.setSpacing(10);
layout.getChildren().addAll(moistureCheckLabelHuge,moistureCheckTextField,countinueButton,finishButton);
Scene scene = new Scene(layout, 600, 500); Scene scene = new Scene(layout, 600, 500);
scene.getStylesheets().add(InputPopUpWindow.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm()); scene.getStylesheets().add(InputPopUpWindow.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
......
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment