#8: Implement Login Logic
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
b9eae8088f
commit
b617e8c242
4 changed files with 52 additions and 11 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -43,7 +43,12 @@ public class UserDao implements Dao<User> {
|
|||
@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<User> {
|
|||
@Override
|
||||
public List<User> 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
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
</center>
|
||||
<bottom>
|
||||
<Button
|
||||
fx:id="buttonSubmit"
|
||||
text="Bestätigen"
|
||||
BorderPane.alignment="CENTER"
|
||||
onAction="#handleSubmit"
|
||||
|
|
Loading…
Reference in a new issue