@Override public User getUser(String username) { User user = dao.findByUsername(username.toLowerCase()); if (user != null) { if (user.getSif() != null) { return user; } return user; } return null; }
@Override public boolean login(String username, String password) { log.info(username + " - " + password); User user = dao.findByUsername(username.toLowerCase()); if (user != null) { if (user.getPassword() == null) { return true; } return JCrypt.check(password, user.getPassword()); } return false; }
@Override public List<User> loadUsersByIndustry(int id) { List<User> lista = new ArrayList<User>(); List<User> listaAllUsers = loadAll(); for (User u : listaAllUsers) { if (u.getSif() == null) continue; if (id == u.getSif().getEmpresa().getId()) { lista.add(u); } } return lista; }
@Override public int createUser(String name, String username, String password, int perfil) { log.debug(username + " " + password + " " + perfil); User user = new User(); user.setUser(username); user.setPassword(password); user.setGrtUser(name); user.setPerfil(userPerfilDao.get(perfil)); user.setEnabled(1); user = dao.saveOrUpdate(user); return user.getId(); }
@Override public boolean save(User user) { user.setEnabled(1); if (user.getPassword().contains("???")) { user.setPassword(user.getPassword().substring(3)); } else { user.setPassword(JCrypt.encrypt(user.getPassword())); } user = dao.saveOrUpdate(user); return true; }