diff --git a/src/main/java/de/hitec/nhplus/Main.java b/src/main/java/de/hitec/nhplus/Main.java index 1ebffd0..52813b3 100644 --- a/src/main/java/de/hitec/nhplus/Main.java +++ b/src/main/java/de/hitec/nhplus/Main.java @@ -36,7 +36,6 @@ public class Main extends Application { public void start(Stage primaryStage) { this.primaryStage = primaryStage; executePassword(); - //executeMainApplication(); } private void executePassword() { @@ -55,7 +54,7 @@ public class Main extends Application { loginStage.showAndWait(); - if(controller.loginSucessfull){ + if(controller.user == null){ executeMainApplication(); } } catch (IOException exception) { diff --git a/src/main/java/de/hitec/nhplus/login/LoginController.java b/src/main/java/de/hitec/nhplus/login/LoginController.java index 52d5b19..dca1cd7 100644 --- a/src/main/java/de/hitec/nhplus/login/LoginController.java +++ b/src/main/java/de/hitec/nhplus/login/LoginController.java @@ -2,11 +2,14 @@ package de.hitec.nhplus.login; import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.login.database.UserDao; -import javafx.event.ActionEvent; +import javafx.animation.PauseTransition; +import javafx.animation.TranslateTransition; import javafx.fxml.FXML; +import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.stage.Stage; +import javafx.util.Duration; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; @@ -16,27 +19,54 @@ import java.util.Arrays; public class LoginController { + public User user; @FXML public TextField textFieldUsername; @FXML public PasswordField passwordField; + @FXML + public Button buttonSubmit; private Stage stage; - public boolean loginSucessfull = false; private int loginTries = 0; + public void initialize(Stage stage) { this.stage = stage; } - private void handleWrongPasswordOrUsername(){ + private void handleWrongPasswordOrUsername() { loginTries++; - if(loginTries == 3){ - stage.close(); - } + + // Shake + TranslateTransition ttUsername = new TranslateTransition(Duration.millis(50), textFieldUsername); + ttUsername.setByX(10); + ttUsername.setAutoReverse(true); + ttUsername.setCycleCount(6); + + TranslateTransition ttPassword = new TranslateTransition(Duration.millis(50), passwordField); + ttPassword.setByX(10); + ttPassword.setAutoReverse(true); + ttPassword.setCycleCount(6); + + ttUsername.play(); + ttPassword.play(); + + // Timout + PauseTransition pause = new PauseTransition(Duration.seconds(3)); + pause.setOnFinished(event -> { + if (loginTries == 3) { + stage.close(); + } + buttonSubmit.setDisable(false); + }); + pause.play(); + } @FXML public void handleSubmit() { + buttonSubmit.setDisable(true); + UserDao dao = DaoFactory.getInstance().createUserDAO(); try { int id = dao.readUserId(textFieldUsername.getText()); @@ -53,7 +83,7 @@ public class LoginController { handleWrongPasswordOrUsername(); return; } - loginSucessfull = true; + user = dao.read(id); stage.close(); } catch (SQLException | NoSuchAlgorithmException exception) { exception.printStackTrace(); diff --git a/src/main/java/de/hitec/nhplus/login/database/UserDao.java b/src/main/java/de/hitec/nhplus/login/database/UserDao.java index 6ea36ce..8807ca1 100644 --- a/src/main/java/de/hitec/nhplus/login/database/UserDao.java +++ b/src/main/java/de/hitec/nhplus/login/database/UserDao.java @@ -43,7 +43,12 @@ public class UserDao implements Dao { @Override public User read(int id) throws SQLException { final String SQL = """ - SELECT user.username, user.passwordSalt, user.passwordHash, user__permissions.permissions, user__nurse.nurseId + SELECT + user.username, + user.passwordSalt, + user.passwordHash, + user__permissions.permissions, + user__nurse.nurseId FROM user LEFT JOIN user__permissions ON user.id = user__permissions.userId LEFT JOIN user__nurse ON user.id = user__nurse.userId @@ -174,7 +179,13 @@ public class UserDao implements Dao { @Override public List readAll() throws SQLException { final String SQL = """ - SELECT user.id, user.username, user.passwordSalt, user.passwordHash, user__permissions.permissions, user__nurse.nurseId + SELECT + user.id, + user.username, + user.passwordSalt, + user.passwordHash, + user__permissions.permissions, + user__nurse.nurseId FROM user LEFT JOIN user__permissions ON user.id = user__permissions.userId LEFT JOIN user__nurse ON user.id = user__nurse.userId diff --git a/src/main/resources/de/hitec/nhplus/login/LoginView.fxml b/src/main/resources/de/hitec/nhplus/login/LoginView.fxml index 8cf444f..234ff7b 100644 --- a/src/main/resources/de/hitec/nhplus/login/LoginView.fxml +++ b/src/main/resources/de/hitec/nhplus/login/LoginView.fxml @@ -38,6 +38,7 @@