Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LogareController implements Initializable {
- LoginVerifier loginVerifier = new LoginVerifier();
- @FXML
- private TextField Numeutilzator;
- @FXML
- private PasswordField Parola;
- @FXML
- private Label Stare;
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- if (loginVerifier.Conexiune()) {
- Stare.setText("");
- } else {
- Stare.setText("Conexiune nereusita!");
- }
- }
- public void Autentificare (ActionEvent event) {
- try {
- if(loginVerifier.testaredate(Numeutilzator.getText(), Parola.getText())) {
- Stare.setText("Autentificare reusita !");
- ((Node)event.getSource()).getScene().getWindow().hide();
- Stage st= new Stage();
- FXMLLoader loader= new FXMLLoader();
- Pane Pane = loader.load(getClass().getResource("/LicentaApp/Meniu.fxml").openStream());
- Scene scene = new Scene(Pane);
- scene.getStylesheets().add(getClass().getResource("Style1212.css").toExternalForm());
- st.setScene(scene);
- st.show();
- }
- else {
- Stare.setText("Nume de utilizator sau parola incorect");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @FXML
- public void Inregistrare(ActionEvent event) {
- try {
- ((Node)event.getSource()).getScene().getWindow().hide();
- Stage PS= new Stage();
- FXMLLoader loader= new FXMLLoader();
- Pane Pane1 = loader.load(getClass().getResource("/LicentaApp/InregistrareUser.fxml").openStream());
- Scene scena = new Scene(Pane1);
- scena.getStylesheets().add(getClass().getResource("Style1212.css").toExternalForm());
- PS.setScene(scena);
- PS.show();
- } catch (Exception e) {
- }
- }
- // This is what I came up with, I know its bad, but I can't think of anything else, in this method I am trying to save the value of "Admin" from the table in a variable, which I can you to determen if the user has 0 or 1 at the admin, If he has 1 then a new fxml will be loaded for him, if he has 0 he is a
- regular user
- public boolean admin(int admin) throws SQLException {
- ConectaredB ConectaredB=new ConectaredB();
- Connection conectare=ConectaredB.logareDB();
- PreparedStatement PSMG= null;
- ResultSet RSMG = null;
- String Interogare = "SELECT Admin FROM accounts where Admin='1'";
- try {
- PSMG = conectare.prepareStatement(Interogare);
- PSMG.setLong(1, admin);
- LogareController Adminstatus = new LogareController();
- String Adminstatus = admin.getBytes() //IT only lets me to use getBytes(), i wanted to get the value from admin, after the query executed, this causes a confict with the primitive type "int".
- } catch (Exception exceptie2) {
- return true;
- }
- return false;
- }
- }
- }
- public class LoginVerifier {
- public LoginVerifier () {
- ConectaredB ConectaredB=new ConectaredB();
- Connection conectare=ConectaredB.logareDB();
- if (conectare == null) {
- System.out.println("Conectare nereusita!");
- System.exit(1);}
- }
- public boolean Conexiune() {
- ConectaredB ConectaredB=new ConectaredB();
- Connection conectare=ConectaredB.logareDB();
- try {
- return !conectare.isClosed();
- } catch (SQLException e) {
- e.printStackTrace();
- return false;
- }
- }
- public boolean testaredate(String numeutil, String parola) throws SQLException {
- ConectaredB ConectaredB=new ConectaredB();
- Connection conectare=ConectaredB.logareDB();
- PreparedStatement PSMG= null;
- ResultSet RSMG = null;
- String Interogare = "SELECT * FROM accounts where Username=? and Password=?";
- try {
- PSMG = conectare.prepareStatement(Interogare);
- PSMG.setString(1, numeutil);
- PSMG.setString(2, parola);
- RSMG = PSMG.executeQuery();
- if(RSMG.next()){
- return true;
- }
- else {
- return false;
- }
- } catch (Exception exceptie2) {
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment