Exemple #1
0
  private UserBalanceVO userBalancePojoToVo(UserBalance userBalance) {
    UserBalanceVO vo = new UserBalanceVO();

    vo.setIdUserBalance(userBalance.getIdUSerBalance());
    vo.setImeis(userBalance.getImeis());
    vo.setResults(userBalance.getResults());
    vo.setSendAlerts(userBalance.getSendAlerts());
    vo.setSurveys(userBalance.getSurveys());
    vo.setUser(userPojoToVo(userBalance.getUser()));
    vo.setUsers(userBalance.getUsers());

    return vo;
  }
Exemple #2
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;
  }