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(); } } }
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; }
public UserVO checkValidationKey(String validationKey) throws MSMApplicationException { Query query = manager.createNamedQuery("user.findByvalidationKey"); query.setParameter("userValidationKey", validationKey); NdgUser user = null; UserVO vo = null; try { user = (NdgUser) query.getSingleResult(); if (user.getUserValidated() == 'n' || user.getUserValidated() == 'N') { user.setUserValidated('Y'); manager.merge(user); } vo = userPojoToVo(user); } catch (NoResultException e) { throw new UserNotFoundException(); } return vo; }
@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; }