#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) {
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) {

View file

@ -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() {
loginTries++;
// 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();

View file

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