Exemple #1
0
 public void updateUserPassword(UserVO userToUpdate) throws MSMApplicationException {
   NdgUser user = findNdgUserByName(userToUpdate.getUsername());
   if (userToUpdate.getPassword() != null) {
     try {
       user.setPassword(MD5.createMD5(userToUpdate.getPassword()));
       user.setUserValidated('Y');
     } catch (NoSuchAlgorithmException e) {
       e.printStackTrace();
     }
   }
 }
Exemple #2
0
  public UserVO createUser(UserVO vo) throws MSMApplicationException {
    UserVO newUser = null;
    NdgUser userPending = findNdgUserByName(vo.getUsername());
    UserVO userByEmail = getUserByEmail(vo.getEmail());

    if (userPending != null) {
      throw new UserAlreadyExistException();
    } else if (userByEmail != null) {
      throw new EmailAlreadyExistException();
    } else {
      userPending = new NdgUser();
      try {
        userPending.setPassword(MD5.createMD5(vo.getPassword()));
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      }
      userPending.setUsername(vo.getUsername());
      userPending.setFirstName(vo.getFirstName());
      userPending.setLastName(vo.getLastName());
      userPending.setEmail(vo.getEmail());

      userPending.setPhoneNumber(vo.getPhoneNumber());
      userPending.setAreaCode(vo.getAreaCode());
      userPending.setCountryCode(vo.getCountryCode());

      NdgRole role = findNdgRoleByName(vo.getRole().getName());
      if (role != null) {
        userPending.setRole(role);
      }
      NdgUser userAdmin = findNdgUserByName(vo.getUserAdmin());
      if (userPending != null) {
        userPending.setUserAdmin(userAdmin.getUsername());
        userPending.setCompany(userAdmin.getCompany());
        userPending.setEmailPreferences(userAdmin.getEmailPreferences());
        userPending.setWhoUseIt(userAdmin.getWhoUseIt());
      }

      userPending.setValidationKey(generateValidationKey(vo.getEmail()));
      userPending.setHasFullPermissions(vo.getHasFullPermissions());
      userPending.setUserValidated('Y');
      userPending.setHowDoYouPlanUseNdg("");
      userPending.setFirstTimeUse('Y');

      manager.persist(userPending);

      newUser = userPojoToVo(userPending);
    }

    return newUser;
  }
Exemple #3
0
  public void updateUser(UserVO userToUpdate) throws MSMApplicationException {
    NdgUser user = findNdgUserByName(userToUpdate.getUsername());

    if (user != null) {
      if (userToUpdate.getFirstName() != null) {
        user.setFirstName(userToUpdate.getFirstName());
      }
      if (userToUpdate.getLastName() != null) {
        user.setLastName(userToUpdate.getLastName());
      }
      if (userToUpdate.getEmail() != null) {
        user.setEmail(userToUpdate.getEmail());
      }
      if (userToUpdate.getCountryCode() != null) {
        user.setCountryCode(userToUpdate.getCountryCode());
      }
      if (userToUpdate.getAreaCode() != null) {
        user.setAreaCode(userToUpdate.getAreaCode());
      }
      if (userToUpdate.getPhoneNumber() != null) {
        user.setPhoneNumber(userToUpdate.getPhoneNumber());
      }
      if (userToUpdate.getRole() != null) {
        NdgRole role = findNdgRoleByName(userToUpdate.getRole().getName());
        if (role != null) {
          user.setRole(role);
        }
      }
      if (userToUpdate.getPassword() != null) {
        try {
          user.setPassword(MD5.createMD5(userToUpdate.getPassword()));
        } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
        }
      }

      user.setFirstTimeUse(userToUpdate.getFirstTimeUse());

      // if (userToUpdate.getHasFullPermissions() == 'y' ||
      //		userToUpdate.getHasFullPermissions() == 'Y') {
      //	user.setHasFullPermissions(userToUpdate.getHasFullPermissions());
      // }
      // user.setFirstTimeUse(userToUpdate.getFirstTimeUse());

      manager.merge(user);
    } else {
      throw new UserNotFoundException();
    }
  }
Exemple #4
0
  public UserVO validateLogin(String username, String password) throws MSMApplicationException {
    NdgUser user = findNdgUserByName(username);
    UserVO vo = new UserVO();

    if (user != null) {
      try {
        if (user.getPassword().equals(MD5.createMD5(password))) {
          if ((user.getUserValidated() == 'y' || user.getUserValidated() == 'Y')) {
            vo = userPojoToVo(user);
            vo.setRetCode(UserVO.AUTHENTICATED);
            vo.setFirstTimeUse(user.getFirstTimeUse());

            try {
              NdgUser userAdmin = findNdgUserByName(user.getUserAdmin());
              vo.setHasFullPermissions(userAdmin.getHasFullPermissions());
            } catch (Exception e) {
              log.error("validateLogin: userAdmin not found - admin = " + user.getUserAdmin());
            }

            Query query = manager.createNamedQuery("userbalance.findByUserAdmin");
            query.setParameter("useradmin", user.getUserAdmin());
            UserBalance userAdminBalance = null;
            try {
              userAdminBalance = (UserBalance) query.getSingleResult();
            } catch (Exception e) {
              log.info("New user: "******"LIMIT_IMEIS")));
                initialUserBalance.setResults(
                    Integer.parseInt(properties.getProperty("LIMIT_RESULTS")));
                initialUserBalance.setSendAlerts(
                    Integer.parseInt(properties.getProperty("LIMIT_SEND_ALERTS")));
                initialUserBalance.setSurveys(
                    Integer.parseInt(properties.getProperty("LIMIT_SURVEYS")));
                initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin()));
                initialUserBalance.setUsers(Integer.parseInt(properties.getProperty("LIMIT_USER")));
              } catch (Exception e) {
                initialUserBalance.setImeis(0);
                initialUserBalance.setResults(0);
                initialUserBalance.setSendAlerts(0);
                initialUserBalance.setSurveys(0);
                initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin()));
                initialUserBalance.setUsers(0);
              }
              UserBalanceVO balanceVO = new UserBalanceVO();
              balanceVO.setImeis(initialUserBalance.getImeis());
              balanceVO.setResults(initialUserBalance.getResults());
              balanceVO.setSendAlerts(initialUserBalance.getSendAlerts());
              balanceVO.setSurveys(initialUserBalance.getSurveys());
              balanceVO.setUsers(initialUserBalance.getUsers());
              vo.setUserBalance(balanceVO);
              manager.persist(initialUserBalance);
            } else {
              UserBalanceVO balanceVO = new UserBalanceVO();
              balanceVO.setImeis(userAdminBalance.getImeis());
              balanceVO.setResults(userAdminBalance.getResults());
              balanceVO.setSendAlerts(userAdminBalance.getSendAlerts());
              balanceVO.setSurveys(userAdminBalance.getSurveys());
              balanceVO.setUsers(userAdminBalance.getUsers());
              vo.setUserBalance(balanceVO);
            }
          } else {
            vo.setRetCode(UserVO.EMAIL_NOT_VALIDATED);
            throw new UserEmailNotValidatedException();
          }
        } else {
          vo.setRetCode(UserVO.INVALID_PASSWORD);
          throw new InvalidPasswordException();
        }
      } catch (NoSuchAlgorithmException e) {
        throw new InvalidPasswordGenerationException();
      }
    } else {
      vo.setRetCode(UserVO.INVALID_USERNAME);
      throw new InvalidUsernameException();
    }
    return vo;
  }
Exemple #5
0
  @Override
  public UserVO requestAccess(UserVO vo) throws MSMApplicationException, MSMSystemException {
    idSimpleSurvey = MD5.createIdSurvey();

    userDirectories =
        properties.getProperty(PropertiesUtil.SURVEY_ROOT)
            + SystemUtils.FILE_SEP
            + vo.getUsername()
            + SystemUtils.FILE_SEP
            + "survey"
            + idSimpleSurvey;

    UserVO newUser = null;

    NdgUser userPending = findNdgUserByName(vo.getUsername());
    if (userPending != null) {
      throw new UserAlreadyExistException();
    }
    UserVO userByEmail = getUserByEmail(vo.getEmail());
    if (userByEmail != null) {
      throw new EmailAlreadyExistException();
    }

    userPending = new NdgUser();
    userPending.setUsername(vo.getUsername());
    try {
      userPending.setPassword(MD5.createMD5(vo.getPassword()));
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      userPending.setPassword(vo.getPassword());
    }

    userPending.setFirstName(vo.getFirstName());
    userPending.setLastName(vo.getLastName());
    userPending.setEmail(vo.getEmail());
    userPending.setWhoUseIt(vo.getWhoUseIt());
    userPending.setPhoneNumber(vo.getPhoneNumber());

    NdgRole role = findNdgRoleByName(vo.getRole().getName());
    if (role != null) {
      userPending.setRole(role);
    }

    Company company = findCompanyByName(vo.getCompany().getCompanyName());
    if (company != null) {
      userPending.setCompany(company);
    } else {
      Company newCompany = new Company();
      newCompany.setCompanyName(vo.getCompany().getCompanyName());
      newCompany.setCompanyType(vo.getCompany().getCompanyType());
      newCompany.setCompanyCountry(vo.getCompany().getCompanyCountry());
      newCompany.setCompanyIndustry(vo.getCompany().getCompanyIndustry());
      newCompany.setCompanySize(vo.getCompany().getCompanySize());
      userPending.setCompany(newCompany);
    }

    userPending.setAreaCode(vo.getAreaCode());
    userPending.setCountryCode(vo.getCountryCode());
    userPending.setEmailPreferences(vo.getEmailPreferences());
    userPending.setHowDoYouPlanUseNdg(vo.getHowDoYouPlanUseNdg());
    userPending.setValidationKey(generateValidationKey(vo.getEmail()));
    userPending.setUserValidated(vo.getUserValidated());
    userPending.setUserAdmin(userPending.getUsername());
    userPending.setFirstTimeUse(vo.getFirstTimeUse());
    userPending.setHasFullPermissions(vo.getHasFullPermissions());

    manager.persist(userPending);
    createUserFile(vo.getUsername());
    newUser = userPojoToVo(userPending);

    return newUser;
  }