public void validateUserAccountOnly(Users human) { if (human.getPassword() == null || human.getPassword().trim().compareTo("") == 0) { throw new ValidateInputException(ResourceMessages.getResource("user_not_enter_password")); } if (human.getRetypePassword() == null || human.getRetypePassword().trim().compareTo("") == 0) { throw new ValidateInputException( ResourceMessages.getResource("user_not_enter_retype_password")); } if (human.getRetypePassword().toLowerCase().compareTo(human.getPassword().toLowerCase()) != 0) { throw new ValidateInputException(ResourceMessages.getResource("user_password_not_march")); } if (human.getUserId() == null) { DataValidator.validateUsernameAsEmail(human.getUsername()); Users u = this.userService.getUserByUsername(human.getUsername()); if (u != null) { // if (human.getUserId() == null) { // them moi user name da ton tai throw new ValidateInputException(ResourceMessages.getResource("user_username_exist")); // } // if (u.getUserId().longValue() != human.getUserId().longValue()) { // throw new // ValidateInputException(ResourceMessages.getResource("user_username_exist")); // } } } human.setPassword(HashData.hashDocument(human.getPassword())); }
public void validateHumanOnly(HumanDto human, Organization organization, HumanType humanType) { if (((organization == null || organization.getOrganizationId() == null) && humanType.toInteger() == HumanType.STAFF.toInteger()) // chi check truong hop khong quan ly mo hinh to chuc ) { throw new ValidateInputException( ResourceMessages.getResource("user_not_choice_organization")); } if (human.getFullName() == null || human.getFullName().trim().compareTo("") == 0) { throw new ValidateInputException(ResourceMessages.getResource("user_not_enter_fullname")); } if (human.getGender() == -1) { throw new ValidateInputException(ResourceMessages.getResource("user_choice_gender")); } if (human.getBirthday() == null) { throw new ValidateInputException(ResourceMessages.getResource("user_enter_brithday")); } else if (!human.getBirthday().before(new Date())) { throw new ValidateInputException( ResourceMessages.getResource("user_enter_brithday_invalide")); } if (human.getEmailAddress() != null || human.getEmailAddress().trim().compareTo("") != 0) { human.setEmailAddress(human.getEmailAddress().trim()); DataValidator.validateEmailAdress(human.getEmailAddress()); if (humanType.toInteger() == HumanType.RETAIL_CUSTOMER.toInteger() && humanService.validateCustomerByEmail( human.getEmailAddress(), AuthenticationController.getCurrentRootOrg(), human.getHumanId())) { MessagesExceptionUtils.addErrorMessages( "Địa chỉ email " + human.getEmailAddress() + " đã tồn tại. Vui lòng sử dụng địa chỉ email khác."); } else if (humanService.validateHumanByEmail( human.getEmailAddress(), AuthenticationController.getCurrentRootOrg(), human.getHumanId())) { MessagesExceptionUtils.addErrorMessages( "Địa chỉ email " + human.getEmailAddress() + " đã tồn tại. Vui lòng sử dụng địa chỉ email khác."); } } human.setFullName(DataValidator.deleteSpace(DataValidator.standardName(human.getFullName()))); human.setAddress(DataValidator.deleteSpace(DataValidator.standardName(human.getAddress()))); }
public void validateHuman(HumanDto human, Organization organization, HumanType humanType) { if (((organization == null || organization.getOrganizationId() == null) && humanType.toInteger() == HumanType.STAFF.toInteger()) // chi check truong hop khong quan ly mo hinh to chuc ) { throw new ValidateInputException( ResourceMessages.getResource("user_not_choice_organization")); } if (human.getFullName() == null || human.getFullName().trim().compareTo("") == 0) { throw new ValidateInputException(ResourceMessages.getResource("user_not_enter_fullname")); } if (human.getGender() == -1) { throw new ValidateInputException(ResourceMessages.getResource("user_choice_gender")); } if (human.getBirthday() == null) { throw new ValidateInputException(ResourceMessages.getResource("user_enter_brithday")); } else if (!human.getBirthday().before(new Date())) { throw new ValidateInputException( ResourceMessages.getResource("user_enter_brithday_invalide")); } if (human.getUsername() != null && human.getUsername().trim().compareTo("") != 0) { if (human.getUserId() == null || (human.getUserId() != null && ((human.getPassword() != null && human.getPassword().compareTo("") != 0) || (human.getRetypePassword() != null) && human.getRetypePassword().compareTo("") != 0))) { if (human.getUserId() == null) { DataValidator.validateUsername(human.getUsername()); } if (human.getPassword() == null || human.getPassword().trim().compareTo("") == 0) { throw new ValidateInputException(ResourceMessages.getResource("user_not_enter_password")); } if (human.getRetypePassword() == null || human.getRetypePassword().trim().compareTo("") == 0) { throw new ValidateInputException( ResourceMessages.getResource("user_not_enter_retype_password")); } if (human.getRetypePassword().toLowerCase().compareTo(human.getPassword().toLowerCase()) != 0) { throw new ValidateInputException(ResourceMessages.getResource("user_password_not_march")); } } } // if (human.getAddress() == null || human.getAddress().trim().compareTo("") == 0) { // throw new // ValidateInputException(ResourceMessages.getResource("not_enter_address")); // } if (human.getEmailAddress() != null || human.getEmailAddress().trim().compareTo("") != 0) { human.setEmailAddress(human.getEmailAddress().trim()); DataValidator.validateEmailAdress(human.getEmailAddress()); if (humanType.toInteger() == HumanType.RETAIL_CUSTOMER.toInteger() && humanService.validateCustomerByEmail( human.getEmailAddress(), AuthenticationController.getCurrentRootOrg(), human.getHumanId())) { MessagesExceptionUtils.addErrorMessages( "Địa chỉ email " + human.getEmailAddress() + " đã tồn tại. Vui lòng sử dụng địa chỉ email khác."); } else if (humanService.validateHumanByEmail( human.getEmailAddress(), AuthenticationController.getCurrentRootOrg(), human.getHumanId())) { MessagesExceptionUtils.addErrorMessages( "Địa chỉ email " + human.getEmailAddress() + " đã tồn tại. Vui lòng sử dụng địa chỉ email khác."); } } human.setFullName(DataValidator.deleteSpace(DataValidator.standardName(human.getFullName()))); human.setAddress(DataValidator.deleteSpace(DataValidator.standardName(human.getAddress()))); if (human.getUsername() != null && human.getUsername().trim().compareTo("") != 0) { Users u = this.userService.getUserByUsername(human.getUsername()); if (u != null) { if (human.getUserId() == null) { // them moi user name da ton tai throw new ValidateInputException(ResourceMessages.getResource("user_username_exist")); } if (u.getUserId().longValue() != human.getUserId().longValue()) { throw new ValidateInputException(ResourceMessages.getResource("user_username_exist")); } } if (u == null) { // them moi thi ma hoa password luon human.setPassword(HashData.hashDocument(human.getPassword())); } else if (human.getPassword() != null && human.getPassword().compareTo("") != 0) { // ko phai them moi thi phai kiem tra xem password co khac nhau ko human.setPassword(HashData.hashDocument(human.getPassword())); } else { human.setPassword(u.getPassword()); } } }