/**
   * Creates a new user.
   *
   * @param firstName The first name of the user
   * @param lastName The last name of the user
   * @param email The email address of the user
   * @param username The username of the user
   * @param password The password of the user
   * @param role The role of the user
   * @return The created user
   */
  public User createUser(
      String firstName,
      String lastName,
      String email,
      String username,
      String password,
      Role role) {
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();

    try {
      String passwordEncoded = EncodingUtils.md5EncodeString(password);
      InternalAuth internalAuth = internalAuthDAO.create(username, passwordEncoded);
      User user =
          userDAO.create(
              firstName, lastName, String.valueOf(internalAuth.getId()), getName(), role);
      // TODO Default contact type?
      emailDAO.create(user.getContactInfo(), null, Boolean.TRUE, email);
      return user;
    } catch (UnsupportedEncodingException e) {
      throw new SmvcRuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
      throw new SmvcRuntimeException(e);
    }
  }
Example #2
0
  private UserVariable create(User user, UserVariableKey key, String value) {
    EntityManager entityManager = getEntityManager();

    UserVariable userVariable = new UserVariable();
    userVariable.setUser(user);
    userVariable.setKey(key);
    userVariable.setValue(value);
    entityManager.persist(userVariable);

    user.getVariables().add(userVariable);
    entityManager.persist(user);

    return userVariable;
  }