After Registration, I want to verify the information of the user, After verifying the information by admin - He will be able to log in. How can I do it by JavaFX?
In my code if anyone registers he can login by this time but I want to verify his/her information, if his all information is correct then he will be able to log in for the next activity, otherwise i want to reject his registration.
Here is my database connection snippet:
public static void signUpUser(ActionEvent event, String username, String email, String password) {
Connection connection = null;
PreparedStatement psInsert = null;
PreparedStatement psCheckUserExists = null;
ResultSet resultSet = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DTABASE_TABLE", "root", "");
psCheckUserExists = connection.prepareStatement("SELECT * FROM user_info WHERE email = ?");
psCheckUserExists.setString(1, email);
resultSet = psCheckUserExists.executeQuery();
if (resultSet.isBeforeFirst()) {
System.out.println("Email Already Exits");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("You can not use this email");
alert.show();
} else {
psInsert = connection.prepareStatement("INSERT INTO user_info (username, email, password) VALUES (?, ?, ?)");
psInsert.setString(1, username);
psInsert.setString(2, email);
psInsert.setString(3, password);
psInsert.executeUpdate();
changeScene(event, "homePage.fxml", "Welcome ", username);
}
}
}
public static void logInUser(ActionEvent event, String email, String password) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DATABASE_TABLE", "root", "");
preparedStatement = connection.prepareStatement("SELECT password FROM user_info WHERE email = ?");
preparedStatement.setString(1, email);
resultSet = preparedStatement.executeQuery();
if (!resultSet.isBeforeFirst()) {
System.out.println("User Not Found in the Database");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("Provide credential are incorrect");
alert.show();
} else {
while (resultSet.next()) {
String retrievedPassword = resultSet.getString("password");
//String retrievedChannel = resultSet.getString("username");
if (retrievedPassword.equals(password)) {
changeScene(event, "homePage.fxml", "welcome ", email);
} else {
System.out.println("Password did not match");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("The provide credentials are incorrect");
alert.show();
}
}
}
}
}