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

Added check for union and length

parent 0d0022e5
No related branches found
No related tags found
No related merge requests found
......@@ -58,13 +58,13 @@
<orderEntry type="library" name="Maven: org.jblas:jblas:1.2.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.9.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.9.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.9.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.9.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.9.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.9.0-M1" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -184,7 +184,7 @@ public static boolean isValidInput (String input){
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
return true;
}
else if(input.contains("UNION")){
else if(input.toLowerCase().contains("union")){
NotificationPopUp.displayNotificationWindow("Keyword: 'UNION' is not allowed");
return true;
}
......
......@@ -134,38 +134,42 @@ public class InputPopup {
if(getLogin().getText().equals("Login")){
err = true;
NotificationPopUp.displayNotificationWindow("Please login!");
}
// If the input is null, sets the value to be empty
if (treeSpeciesList.getValue() == null) {
Constants.TREE_SPECIES = "";
} else if (isValidInput(treeSpeciesList.getValue())) {
treeSpeciesList.setValue("");
err = true;
}
if (dimensionsList.getValue() == null) {
Constants.DIMENSIONS = "";
} else if (dimensionsList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
dimensionsList.setValue("");
err = true;
}
if (sawsetList.getValue() == null) {
Constants.SAWSET = "";
} else if (sawsetList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
sawsetList.setValue("");
err = true;
}
if (moistureList.getValue() == null) {
Constants.MOISTURE_GOAL = "";
} else if (moistureList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
moistureList.setValue("");
}
System.out.println(getLogin().getText());
System.out.println("TREE_SPECIES: "+ Constants.TREE_SPECIES);
System.out.println("DIMENSIONS: "+ Constants.DIMENSIONS);
System.out.println("SAWSET: "+ Constants.SAWSET);
System.out.println("MOISTURE_GOAL: "+ Constants.MOISTURE_GOAL);
// Validates inputs
if(isValidInput(Constants.TREE_SPECIES) ||
isValidInput(Constants.DIMENSIONS) ||
isValidInput(Constants.SAWSET) ||
isValidInput(Constants.MOISTURE_GOAL)) {
err = true;
treeSpeciesList.setValue("");
dimensionsList.setValue("");
sawsetList.setValue("");
moistureList.setValue("");
}
......@@ -249,7 +253,7 @@ public class InputPopup {
}
} else {
NotificationPopUp.displayNotificationWindow("Please login!");
}
}
......
......@@ -15,6 +15,7 @@ import java.security.MessageDigest;
import static com.application.DB.AccountHandler.*;
import static com.application.DB.Constants.*;
import static com.application.DB.HelpingFunctions.isValidInput;
import static com.application.GUI.Panes.CreateLogoBar.getLogin;
public class LoginPopup {
......@@ -57,16 +58,20 @@ public class LoginPopup {
closeButton.setOnAction(event -> window.close());
getPasswordTextField().setOnKeyPressed( event -> {
if( event.getCode() == KeyCode.ENTER ) {
if(loginButtonPressed()){
window.close();
if (event.getCode() == KeyCode.ENTER) {
if(!isValidInput(getPasswordTextField().getText()) && !isValidInput(getUsernameTextField().getText())) {
if (loginButtonPressed()) {
window.close();
}
}
}
});
loginButton.setOnAction(event -> {
if(loginButtonPressed()){
window.close();
if(!isValidInput(getPasswordTextField().getText()) && !isValidInput(getUsernameTextField().getText())) {
if (loginButtonPressed()) {
window.close();
}
}
});
......@@ -150,6 +155,13 @@ public class LoginPopup {
close.setOnAction(event -> window.close());
addUser.setOnAction(event -> {
// Validate input parameters
if(!isValidInput(firstNameTextField.getText()) &&
!isValidInput(lastNameTextField.getText()) &&
!isValidInput(phoneNoTextField.getText()) &&
!isValidInput(usernameTextField.getText()) &&
!isValidInput(passwordFirstField.getText()) &&
!isValidInput(passwordSecondField.getText())) {
// If the passwords match each other, add the user, if not display an errormessage
if(passwordFirstField.getText().contentEquals(passwordSecondField.getText())){
......@@ -166,7 +178,7 @@ public class LoginPopup {
} catch (Exception e) {
e.printStackTrace();
}
} else {
} }else {
NotificationPopUp.displayNotificationWindow("Passwords does not match!");
passwordFirstField.clear();
passwordSecondField.clear();
......@@ -202,17 +214,19 @@ public class LoginPopup {
close.setOnAction(event -> window.close());
delete.setOnAction(event -> {
try {
boolean results = deleteUser(usernameTextField.getText());
if(results){
NotificationPopUp.displayNotificationWindow(usernameTextField.getText()+" was successfully deleted!");
window.close();
} else {
NotificationPopUp.displayNotificationWindow("Could not find username: " + usernameTextField.getText());
usernameTextField.clear();
if(!isValidInput(usernameTextField.getText())) {
try {
boolean results = deleteUser(usernameTextField.getText());
if (results) {
NotificationPopUp.displayNotificationWindow(usernameTextField.getText() + " was successfully deleted!");
window.close();
} else {
NotificationPopUp.displayNotificationWindow("Could not find username: " + usernameTextField.getText());
usernameTextField.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
});
......
......@@ -16,6 +16,7 @@ import java.time.format.DateTimeFormatter;
import static com.application.DB.Constants.IS_FINISHED;
import static com.application.DB.Constants.MAX_USER_INPUT_CHARACTERS;
import static com.application.DB.HelpingFunctions.isValidInput;
public class OutputPopup {
......@@ -47,7 +48,8 @@ public class OutputPopup {
boolean err = false;
if(moistureCheckTextField.getCharacters().length() > MAX_USER_INPUT_CHARACTERS){
// Validates inputs
if(isValidInput(moistureCheckTextField.getText())){
err = true;
}
......@@ -82,7 +84,8 @@ public class OutputPopup {
boolean err = false;
if(moistureCheckTextField.getCharacters().length() > MAX_USER_INPUT_CHARACTERS){
// Validates inputs
if(isValidInput(moistureCheckTextField.getText())){
err = true;
}
......
No preview for this file type
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.
Finish editing this message first!
Please register or to comment