public void Login() throws IOException {

    // TODO set username og password til en string istedet for at hent dem på den måde

    // if username field is empty = error message
    if (usernameText.getText().equals("")) {

      passwordErrorLbl.setVisible(false);
      usernameErrorLbl.setVisible(true);

      loginErrorLbl.setVisible(false);
    }
    // if passwordfield is empty = error message
    if (passwordText.getText().equals("")) {

      usernameErrorLbl.setVisible(false);
      passwordErrorLbl.setVisible(true);

      loginErrorLbl.setVisible(false);
    }

    if (passwordText.getText().equals("") && usernameText.getText().equals("")) {

      usernameErrorLbl.setVisible(true);
      passwordErrorLbl.setVisible(true);

      loginErrorLbl.setVisible(false);
    }

    if (logic.userAuth(usernameText.getText(), passwordText.getText())) {

      usernameErrorLbl.setVisible(false);
      passwordErrorLbl.setVisible(false);
      loginErrorLbl.setVisible(false);

      usernameText.clear();
      passwordText.clear();

      // TODO get menu to display currentuser

      myController.setScreen(Main.screenMenuID);

    } else {

      usernameErrorLbl.setVisible(false);
      passwordErrorLbl.setVisible(false);

      loginErrorLbl.setVisible(true);
    }
  }
Пример #2
0
 @FXML
 protected void handleSubmitButtonAction(ActionEvent event) {
   db.Connect();
   boolean test = db.userExist(username.getText().toString());
   if (test) {
     System.out.println("User Exists");
     test = db.checkPassword(username.getText().toString(), password.getText().toString());
     if (test) {
       // if username and password is correct program moves to main screen
       System.out.println("Password is correct");
       myController.setScreen(WellCheck.screenID2);
       db.patientTable();
     }
   }
   username.clear();
   password.clear();
   System.out.println(username.getText().toString());
 }
Пример #3
0
  @Override
  public void initialize(URL url, ResourceBundle rb) {

    try { // Create a socket to connect to the server
      Socket socket = new Socket("localhost", 8000);

      FromServer = new DataInputStream(socket.getInputStream());
      // Create an output stream to send data to the server
      ToServer = new DataOutputStream(socket.getOutputStream());
    } catch (IOException ex) {
      lbout.setText(ex.toString() + '\n');
    }

    while (loged) {}
    btlogout.setOnAction(
        e -> {
          try {
            ToServer.writeUTF("Logout");
            Boolean logout = FromServer.readBoolean();
            if (logout) {
              loged = false;
              isadmin = false;
              lbloginfo.setText("Loged Out");
              tbuser.setDisable(!loged);
              tbadmin.setDisable(!isadmin);
              btlogout.setVisible(false);
              btlogin.setVisible(true);
              txaddpass.clear();
              // btlogin.setText("Login");
              tfname.setDisable(false);
              tfpass.setDisable(false);
            } else lbloginfo.setText("Logout Failed");

          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
        });
    btlogin.setOnAction(
        e -> {
          String name = tfname.getText();
          String pass = tfpass.getText();
          if (name.isEmpty() && pass.isEmpty()) lbloginfo.setText("Username and Password is empty");
          else if (name.isEmpty()) lbloginfo.setText("Username is empty");
          else if (pass.isEmpty()) lbloginfo.setText("Password is empty");
          else {
            try {
              ToServer.writeUTF(tfname.getText());
              ToServer.writeUTF(tfpass.getText());
              loged = FromServer.readBoolean();
              isadmin = FromServer.readBoolean();
              if (loged) {
                lbloginfo.setText("Logged in");
                lbloginfo.setText("Welcome Back " + name);
                // btlogin.setText("Logout");
                tfname.setDisable(true);
                tfpass.setDisable(true);
                btlogin.setVisible(false);
                btlogout.setVisible(true);
                if (isadmin) {
                  lbtypeuser.setText("Loged as Administrator");

                } else lbtypeuser.setText("Loged as User");
                // tbadmin.setDisable(!isadmin);
                tbuser.setDisable(!loged);
                tbadmin.setDisable(!isadmin);
                tb.getSelectionModel().select(tbuser);
                repo = FromServer.readUTF();
                txgroup.setText(repo);
                // getuserinfo(repo);
                getFilesinfo();
                getgroupe();
                getusers();
                gettars();
                // cbbackups.getItems().addAll(tars);
                // cbgroup.getItems().addAll(groups);
                // cbselectuser.getItems().addAll(users);
              } else lbout.setText("Failed to log in");

            } catch (IOException ex) {

            }
          }
        });
    btbackup.setOnAction(
        e -> {
          try {
            tars.clear();
            ToServer.writeUTF("Backup");
            Boolean answer = FromServer.readBoolean();
            if (answer) {
              lbadmininfo.setText("Backup finished");
              gettars();
            } else {
              lbadmininfo.setText("error accured during restore");
              gettars();
            }

          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            try {
              gettars();
            } catch (Exception e2) {
              // TODO Auto-generated catch block
              e2.printStackTrace();
            }
          }
        });
    btrestore.setOnAction(
        e -> {
          try {
            if (!cbbackups.selectionModelProperty().get().getSelectedItem().isEmpty()) {
              ToServer.writeUTF("Restore");
              ToServer.writeUTF(cbbackups.selectionModelProperty().get().getSelectedItem());
              Boolean answer = FromServer.readBoolean();
              if (answer) lbadmininfo.setText("restore finished");
              else lbadmininfo.setText("error accured during backup");
            } else lbadmininfo.setText("please choose tar file");

          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
        });
    btcheckin.setOnAction(
        e -> {
          if (loged) {
            file = fileChooser.showOpenDialog(new Stage());
            if (file != null) {
              try {
                ToServer.writeUTF("Checkin");
                ToServer.writeUTF(file.getName());
                ToServer.writeLong(file.lastModified());
                sendFile(file);
                String choice = null;
                choice = FromServer.readUTF();
                if (choice.equals("sync")) {
                  getFilesinfo();
                  File newfile = GetFile(FromServer);

                  writeFile(file, file.getPath() + "--old");
                  String path = file.getPath();
                  file.delete();
                  writeFile(newfile, path);
                  lbout.setText("Performing Sync with the server");
                } else if (choice.contains("locked")) {
                  getFilesinfo();
                  lbout.setText(choice);
                } else if (choice.equals("not text")) {
                  getFilesinfo();
                  lbout.setText("Check in only text files");
                } else if (choice.equals("equal")) {
                  getFilesinfo();
                  lbout.setText("The file is equal to the latest version");
                } else {
                  getFilesinfo();
                  lbout.setText("The file is uploaded successfully");
                }
                // ToServer.writeUTF("Files");

                // getFilesinfo();
              } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
            }
          }
        });
    btcheckout.setOnAction(
        e -> {
          try {
            ToServer.writeUTF("Checkout");
            ToServer.writeUTF(tbl.selectionModelProperty().get().getSelectedItem().getName());
            System.out.println(tbl.selectionModelProperty().get().getSelectedItem().getName());
            ToServer.writeUTF(cbversion.selectionModelProperty().get().getSelectedItem());
            System.out.println(cbversion.selectionModelProperty().get().getSelectedItem());
            Boolean answer = FromServer.readBoolean();
            if (answer) {
              String filename = FromServer.readUTF();
              Long timestamp = FromServer.readLong();
              File ver = GetFile(FromServer);
              String pa = System.getProperty("user.home") + "/" + filename;
              writeFile(ver, System.getProperty("user.home") + "/" + filename);
              File tim = new File(System.getProperty("user.home") + "/" + filename);
              tim.setLastModified(timestamp);
              lbout.setText("The file is saved on your home directory");
            } else lbout.setText("Checkout failed");
          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
        });
    tbl.getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (obs, oldSelection, newSelection) -> {
              if (newSelection != null) {
                versions.clear();
                Float lastvers =
                    Float.valueOf(tbl.getSelectionModel().selectedItemProperty().get().getLastv());
                for (float i = 1f; i <= lastvers + 0.001; i += 0.001) {
                  if (i == 1f) versions.add(Float.toString(i) + "00");
                  else versions.add(Float.toString(i).substring(0, 5));
                }
                cbversion.getItems().addAll(versions);
              }
            });
    cbgroup
        .getSelectionModel()
        .selectedItemProperty()
        .addListener(
            (obs, oldSelection, newSelection) -> {
              if (newSelection != null) {
                try {

                } catch (Exception e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
                }
              }
            });
    btadduser.setOnAction(
        e -> {
          try {
            if (!txaddname.getText().isEmpty()
                && !txaddpass.getText().isEmpty()
                && !txgroup.getText().isEmpty()) {
              ToServer.writeUTF("Adduser");
              ToServer.writeUTF(txaddname.getText());
              ToServer.writeUTF(txaddpass.getText());
              if (cboxadmin.isSelected()) ToServer.writeUTF("1");
              else ToServer.writeUTF("0");
              ToServer.writeUTF(txgroup.getText());
              Boolean answer = FromServer.readBoolean();
              try {
                if (answer) {
                  lbadmininfo.setText("User Added");
                  users.clear();
                  getusers();
                  // users.add(txaddname.getText());
                  txaddname.setText("");
                  txaddpass.setText("");
                  cboxadmin.setSelected(false);
                } else {
                  lbadmininfo.setText("User add failed");
                  getusers();
                }
              } catch (Exception p) {
                getusers();
              }
            } else {
              lbadmininfo.setText("All text must be field");
              getusers();
            }

          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            try {
              getusers();
            } catch (Exception e2) {
              // TODO Auto-generated catch block
              e2.printStackTrace();
            }
          }
        });
    btdeleteuser.setOnAction(
        e -> {
          try {
            if (!cbselectuser.selectionModelProperty().get().getSelectedItem().isEmpty()) {
              ToServer.writeUTF("Deleteuser");
              ToServer.writeUTF(cbselectuser.selectionModelProperty().get().getSelectedItem());
              cbselectuser.setValue("");
              users.clear();
              Boolean answer = FromServer.readBoolean();
              if (answer) {
                lbadmininfo.setText("User deleted");
                getusers();
                // users.remove(cbselectuser.selectionModelProperty().get().getSelectedItem());
              } else {
                lbadmininfo.setText("unable to delete user");
                getusers();
              }
            } else {
              lbadmininfo.setText("All text must be field");
              getusers();
            }

          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            try {
              getusers();
            } catch (Exception e2) {
              // TODO Auto-generated catch block
              e2.printStackTrace();
            }
          }
        });
    btaddgroup.setOnAction(
        e -> {
          try {
            if (!txgroupname.getText().isEmpty()) {
              ToServer.writeUTF("Addgroup");
              ToServer.writeUTF(txgroupname.getText());
              Boolean answer = FromServer.readBoolean();
              if (answer) {
                lbadmininfo.setText("Group Added");
                getgroupe();
              } else {
                lbadmininfo.setText("Group add failed");
                getgroupe();
              }
            } else {
              lbadmininfo.setText("All text must be field");
              getgroupe();
            }
          } catch (Exception e1) {
            // TODO Auto-generated catch block
            try {
              getgroupe();
            } catch (Exception e2) {
              // TODO Auto-generated catch block
              e2.printStackTrace();
            }
          }
        });
  }