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

Added login for admin and logout functionality, missing add- and delete user

parent 9af9e210
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ public class Account_handler { ...@@ -14,7 +14,7 @@ public class Account_handler {
public static void getAccount(String username, String password) throws Exception { public static void getAccount(String username, String password) throws Exception {
// Sqlstatement // Sqlstatement
final String sqlStatement = "SELECT Username, Admin, Phone_no " + final String sqlStatement = "SELECT Username, Admin, Phone_no, First_name, Last_name " +
"FROM " + PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME + " " + "FROM " + PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME + " " +
"WHERE Username = " + '"' + username + '"' + " " + "WHERE Username = " + '"' + username + '"' + " " +
"AND Password = " + '"' + password+ '"'; "AND Password = " + '"' + password+ '"';
...@@ -30,14 +30,19 @@ public class Account_handler { ...@@ -30,14 +30,19 @@ public class Account_handler {
if (row.get("Username").getValue().equals(username)) { if (row.get("Username").getValue().equals(username)) {
LogoBar.getLogin().setText(username); LogoBar.getLogin().setText(username);
setUserName(username); setUserName(username);
}
if (!row.get("Phone_no").isNull()) {
setPhoneNo(row.get("Phone_no").getStringValue());
}
if (row.get("Admin").getBooleanValue()) { if (!row.get("Phone_no").isNull()) {
setIsAdmin(true); setPhoneNo(row.get("Phone_no").getStringValue());
}
if (!row.get("First_name").isNull()) {
setFirstName(row.get("First_name").getStringValue());
}
if (!row.get("Last_name").isNull()) {
setLastName(row.get("Last_name").getStringValue());
}
if (!row.get("Admin").isNull()) {
setIsAdmin(row.get("Admin").getBooleanValue());
}
} }
} }
} else { } else {
......
...@@ -36,6 +36,8 @@ public class Constants { ...@@ -36,6 +36,8 @@ public class Constants {
// Account constants // Account constants
private static boolean isAdmin = false; private static boolean isAdmin = false;
private static String firstName;
private static String lastName;
private static String userName; private static String userName;
private static String phoneNo; private static String phoneNo;
...@@ -62,4 +64,20 @@ public class Constants { ...@@ -62,4 +64,20 @@ public class Constants {
public static void setIsAdmin(boolean isAdmin) { public static void setIsAdmin(boolean isAdmin) {
Constants.isAdmin = isAdmin; Constants.isAdmin = isAdmin;
} }
public static String getFirstName() {
return firstName;
}
public static void setFirstName(String firstName) {
Constants.firstName = firstName;
}
public static String getLastName() {
return lastName;
}
public static void setLastName(String lastName) {
Constants.lastName = lastName;
}
} }
...@@ -18,6 +18,8 @@ import java.security.SecureRandom; ...@@ -18,6 +18,8 @@ import java.security.SecureRandom;
import java.util.Arrays; import java.util.Arrays;
import static com.application.DB.Account_handler.getAccount; import static com.application.DB.Account_handler.getAccount;
import static com.application.DB.Constants.*;
import static com.application.GUI.Panes.LogoBar.getLogin;
public class LoginPopup { public class LoginPopup {
...@@ -33,6 +35,7 @@ public class LoginPopup { ...@@ -33,6 +35,7 @@ public class LoginPopup {
Label passwordLabel = new Label("Password:"); Label passwordLabel = new Label("Password:");
TextField userNameTextField = new TextField(); TextField userNameTextField = new TextField();
getPasswordTextField().clear();
Button closeButton = new Button("Close"); Button closeButton = new Button("Close");
Button loginButton = new Button("Login"); Button loginButton = new Button("Login");
...@@ -56,7 +59,7 @@ public class LoginPopup { ...@@ -56,7 +59,7 @@ public class LoginPopup {
getAccount(userNameTextField.getText(),hashedPasswordString.toString()); getAccount(userNameTextField.getText(),hashedPasswordString.toString());
if(!LogoBar.getLogin().getText().equals("Login")){ if(!getLogin().getText().equals("Login")){
window.close(); window.close();
} }
...@@ -85,7 +88,55 @@ public class LoginPopup { ...@@ -85,7 +88,55 @@ public class LoginPopup {
Stage window = new Stage(); Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL); window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Login window"); window.setTitle("Admin window");
Label usernameLabel = new Label("Username: ");
TextField usernameTextfield = new TextField();
usernameTextfield.setText(getUserName());
usernameTextfield.setEditable(false);
Button addUser = new Button("Add User");
Button deleteUser = new Button("Delete User");
Button logout = new Button("Logout");
addUser.setOnAction(event -> {
window.close();
adminAddUser();
});
deleteUser.setOnAction(event -> {
window.close();
adminDeleteUser();
});
logout.setOnAction(event -> {
window.close();
logout();
});
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll(usernameLabel, usernameTextfield, addUser, deleteUser, logout);
Scene scene = new Scene(layout, 500, 300);
scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
window.setScene(scene);
window.showAndWait();
}
public static void adminAddUser(){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Admin window");
Label firstNameLabel = new Label("First Name: ");
Label lastNameLabel = new Label("Last Name: ");
Label phoneNoLabel = new Label("Phone No: ");
Label username = new Label("Username: ");
Label passwordFirst = new Label("Password");
VBox layout = new VBox(10); VBox layout = new VBox(10);
...@@ -98,11 +149,20 @@ public class LoginPopup { ...@@ -98,11 +149,20 @@ public class LoginPopup {
window.showAndWait(); window.showAndWait();
} }
public static void userPopup(){ public static void adminDeleteUser(){
Stage window = new Stage(); Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL); window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Login window"); window.setTitle("Admin window");
Label firstNameLabel = new Label("First Name: ");
Label lastNameLabel = new Label("Last Name: ");
Label phoneNoLabel = new Label("Phone No: ");
Label username = new Label("Username: ");
Label passwordFirst = new Label("Password");
VBox layout = new VBox(10); VBox layout = new VBox(10);
...@@ -115,6 +175,43 @@ public class LoginPopup { ...@@ -115,6 +175,43 @@ public class LoginPopup {
window.showAndWait(); window.showAndWait();
} }
public static void logout(){
getLogin().setText("Login");
setFirstName("");
setLastName("");
setIsAdmin(false);
setPhoneNo("");
setUserName("");
}
public static void userPopup(){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("User window");
Label nameLabel = new Label("Name: ");
Label phoneNoLabel = new Label("Phone no: ");
TextField nameTextfield = new TextField();
TextField phoneNoTextField = new TextField();
nameTextfield.setText(getFirstName() + " " + getLastName());
phoneNoTextField.setText(getPhoneNo());
Button logout = new Button("Logout");
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll(nameLabel, nameTextfield, phoneNoLabel, phoneNoTextField, logout);
Scene scene = new Scene(layout, 500, 300);
scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
window.setScene(scene);
window.showAndWait();
}
public static PasswordField getPasswordTextField() { public static PasswordField getPasswordTextField() {
return PASSWORD_TEXT_FIELD; return PASSWORD_TEXT_FIELD;
} }
......
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