예제 #1
0
  private User createNewUser(String email, String password) {

    User user = new User();
    user.setEmail(email);
    user.setPassword(
        CryptoUtil.createPasswordHash("MD5", CryptoUtil.BASE64_ENCODING, null, null, password));
    user.setActive(Boolean.FALSE);
    user.setToken(generateToken());

    return user;
  }
예제 #2
0
  public void saveUserWithRole(String email, String password, Integer roleId)
      throws BusinessValidationException, UserExistException, EmailException {

    if (StringUtils.isNull(email) && StringUtils.isNull(password)) {

      throw new BusinessValidationException("Usuário nulo");
    }

    User userExist = userDAO.findByEmail(email);

    if (userExist != null) {

      throw new UserExistException("Usuário existente");
    }

    Role role = roleDAO.find(roleId);

    if (role == null) {

      throw new BusinessValidationException("Role não existente");
    }

    User user = createNewUser(email, password);

    if (user.getRoles() == null) {

      user.setRoles(new HashSet<Role>());
    }

    user.getRoles().add(role);

    userDAO.save(user);

    emailBS.sendEmailConfirmation(user.getEmail(), user.getToken());
  }