Exemplo n.º 1
0
 private boolean validateFields() {
   if (Utils.safeString(nameTextBox.getValue()).equals("")) {
     MessageBox.alert(textMessages.error(), textMessages.mustEnterName(), null);
     return false;
   }
   if (Utils.safeString(nameTextBox.getValue()).length() > Group.LENGTH_NAME) {
     MessageBox.alert(textMessages.error(), textMessages.tooLongName(), null);
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
  private void doSave() {
    if (validateFields()) {
      user.setUsername(Utils.safeString(usernameTextBox.getValue()));
      user.setFullname(Utils.safeString(fullnameTextBox.getValue()));
      user.setEmail(Utils.safeString(emailTextBox.getValue()));
      user.setActiveFlag(enabledCheckBox.getValue());
      user.updateAuthnPasswordValue(Utils.safeString(password1TextBox.getValue()));
      user.removeGroups();
      for (GroupData groupData : toGroupStore.getModels()) {
        Group group = (Group) groupData.get(Constants.GROUP);
        user.addGroup(group);
      }

      final AsyncCallback<Void> callback =
          new AsyncCallback<Void>() {
            @Override
            public void onFailure(Throwable caught) {
              WebPasswordSafe.handleServerFailure(caught);
            }

            @Override
            public void onSuccess(Void result) {
              Info.display(textMessages.status(), textMessages.userSaved());
              hide();
            }
          };
      if (user.getId() == 0) {
        final AsyncCallback<Boolean> callbackCheck =
            new AsyncCallback<Boolean>() {
              @Override
              public void onFailure(Throwable caught) {
                WebPasswordSafe.handleServerFailure(caught);
              }

              @Override
              public void onSuccess(Boolean result) {
                // true => username already taken, else go ahead and save
                if (result) {
                  MessageBox.alert(
                      textMessages.error(), textMessages.usernameAlreadyExists(), null);
                } else {
                  UserService.Util.getInstance().addUser(user, callback);
                }
              }
            };
        UserService.Util.getInstance().isUserTaken(user.getUsername(), callbackCheck);
      } else {
        UserService.Util.getInstance().updateUser(user, callback);
      }
    }
  }
Exemplo n.º 3
0
  private void doSave() {
    if (validateFields()) {
      group.setName(Utils.safeString(nameTextBox.getValue()));
      group.removeUsers();
      for (UserData userData : toUserStore.getModels()) {
        group.addUser((User) userData.get(Constants.USER));
      }

      final AsyncCallback<Boolean> callbackCheck =
          new AsyncCallback<Boolean>() {
            @Override
            public void onFailure(Throwable caught) {
              WebPasswordSafe.handleServerFailure(caught);
            }

            @Override
            public void onSuccess(Boolean result) {
              // true => group name already taken, else go ahead and save
              if (result) {
                MessageBox.alert(textMessages.error(), textMessages.groupNameAlreadyExists(), null);
              } else {
                AsyncCallback<Void> callback =
                    new AsyncCallback<Void>() {
                      @Override
                      public void onFailure(Throwable caught) {
                        WebPasswordSafe.handleServerFailure(caught);
                      }

                      @Override
                      public void onSuccess(Void result) {
                        Info.display(textMessages.status(), textMessages.groupSaved());
                        hide();
                      }
                    };
                if (group.getId() == 0) {
                  UserService.Util.getInstance().addGroup(group, callback);
                } else {
                  UserService.Util.getInstance().updateGroup(group, callback);
                }
              }
            }
          };
      UserService.Util.getInstance().isGroupTaken(group.getName(), group.getId(), callbackCheck);
    }
  }
Exemplo n.º 4
0
 private boolean validateFields() {
   if (!(Utils.safeString(password2TextBox.getValue()))
       .equals(Utils.safeString(password1TextBox.getValue()))) {
     MessageBox.alert(textMessages.error(), textMessages.passwordsNotMatch(), null);
     return false;
   }
   if (Utils.safeString(password1TextBox.getValue()).length()
       > UserAuthnPassword.LENGTH_PASSWORD) {
     MessageBox.alert(textMessages.error(), textMessages.tooLongPassword(), null);
     return false;
   }
   if (Utils.safeString(usernameTextBox.getValue()).equals("")) {
     MessageBox.alert(textMessages.error(), textMessages.mustEnterUsername(), null);
     return false;
   }
   if (Utils.safeString(usernameTextBox.getValue()).length() > User.LENGTH_USERNAME) {
     MessageBox.alert(textMessages.error(), textMessages.tooLongUsername(), null);
     return false;
   }
   if (Utils.safeString(fullnameTextBox.getValue()).equals("")) {
     MessageBox.alert(textMessages.error(), textMessages.mustEnterFullName(), null);
     return false;
   }
   if (Utils.safeString(fullnameTextBox.getValue()).length() > User.LENGTH_FULLNAME) {
     MessageBox.alert(textMessages.error(), textMessages.tooLongFullName(), null);
     return false;
   }
   if (Utils.safeString(emailTextBox.getValue()).equals("")) {
     MessageBox.alert(textMessages.error(), textMessages.mustEnterEmail(), null);
     return false;
   }
   if (Utils.safeString(emailTextBox.getValue()).length() > User.LENGTH_EMAIL) {
     MessageBox.alert(textMessages.error(), textMessages.tooLongEmail(), null);
     return false;
   }
   if (!Utils.isValidEmail(Utils.safeString(emailTextBox.getValue()))) {
     MessageBox.alert(textMessages.error(), textMessages.invalidEmail(), null);
     return false;
   }
   return true;
 }