#8: Implement Login Logic
Some checks failed
Quality Check / Linting Check (push) Failing after 12s
Quality Check / Javadoc Check (push) Successful in 21s

Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
Dominik Säume 2024-05-21 15:51:48 +02:00
parent b9eae8088f
commit 2009b68ccf
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
3 changed files with 39 additions and 9 deletions

View file

@ -36,7 +36,6 @@ public class Main extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
executePassword(); executePassword();
//executeMainApplication();
} }
private void executePassword() { private void executePassword() {
@ -55,7 +54,7 @@ public class Main extends Application {
loginStage.showAndWait(); loginStage.showAndWait();
if(controller.loginSucessfull){ if(controller.user == null){
executeMainApplication(); executeMainApplication();
} }
} catch (IOException exception) { } catch (IOException exception) {

View file

@ -2,11 +2,14 @@ package de.hitec.nhplus.login;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.login.database.UserDao; 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.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField; import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -16,27 +19,54 @@ import java.util.Arrays;
public class LoginController { public class LoginController {
public User user;
@FXML @FXML
public TextField textFieldUsername; public TextField textFieldUsername;
@FXML @FXML
public PasswordField passwordField; public PasswordField passwordField;
@FXML
public Button buttonSubmit;
private Stage stage; private Stage stage;
public boolean loginSucessfull = false;
private int loginTries = 0; private int loginTries = 0;
public void initialize(Stage stage) { public void initialize(Stage stage) {
this.stage = stage; this.stage = stage;
} }
private void handleWrongPasswordOrUsername(){ private void handleWrongPasswordOrUsername() {
loginTries++; 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 @FXML
public void handleSubmit() { public void handleSubmit() {
buttonSubmit.setDisable(true);
UserDao dao = DaoFactory.getInstance().createUserDAO(); UserDao dao = DaoFactory.getInstance().createUserDAO();
try { try {
int id = dao.readUserId(textFieldUsername.getText()); int id = dao.readUserId(textFieldUsername.getText());
@ -53,7 +83,7 @@ public class LoginController {
handleWrongPasswordOrUsername(); handleWrongPasswordOrUsername();
return; return;
} }
loginSucessfull = true; user = dao.read(id);
stage.close(); stage.close();
} catch (SQLException | NoSuchAlgorithmException exception) { } catch (SQLException | NoSuchAlgorithmException exception) {
exception.printStackTrace(); exception.printStackTrace();

View file

@ -38,6 +38,7 @@
</center> </center>
<bottom> <bottom>
<Button <Button
fx:id="buttonSubmit"
text="Bestätigen" text="Bestätigen"
BorderPane.alignment="CENTER" BorderPane.alignment="CENTER"
onAction="#handleSubmit" onAction="#handleSubmit"