Пример #1
0
  private void doRegister() {

    if (usernameField.getText().isEmpty()) {
      showConsoleText("username missing");
      return;
    }

    if (passwordField.getText().isEmpty()) {
      showConsoleText("password missing");
      return;
    }

    if (emailField.getText().isEmpty()) {
      showConsoleText("email missing");
      return;
    }

    if (userService.findByName(usernameField.getText()) != null) {
      showConsoleText("username taken");
      return;
    }

    userService.addUser(
        new User(usernameField.getText(), passwordField.getText(), emailField.getText()));

    if (userService.findByName(usernameField.getText()) == null) {
      showConsoleText("registration failed");
      return;
    }

    showLogin();
    showConsoleText("registration successful");
  }
Пример #2
0
  private void doLogin() {

    if (usernameField.getText().isEmpty()) {
      showConsoleText("username missing");
      return;
    }

    if (passwordField.getText().isEmpty()) {
      showConsoleText("password missing");
      return;
    }

    if (!userService.authenticate(usernameField.getText(), passwordField.getText())) {
      showConsoleText("authentication failed");
      return;
    }

    showConsoleText("login accepted");
    Navigation.getInstance().loadScreen(MainController.getName());
  }