public User findUserByEmail(String email) { List list = dao.find("from User u where u.email=?", new Object[] {email}); if (list.size() == 1) { return (User) list.get(0); } else if (list.size() > 0) { logger.error("!!!!!!!!!!!!!!!!出现email重名!!!!!!!!!!!!!!!:" + email); } return null; }
public User signUp(User user) { Long count = (Long) dao.find("select count(*) from User u where u.email=?", new Object[] {user.getEmail()}) .get(0); if (count == 0) { dao.save(user); return user; } else { return null; } }
public int clearNewUser() { long msPerDay = 1000 * 24 * 60 * 60; // 一天的毫秒数 Date timeLine = new Date(new Date().getTime() - 2 * msPerDay); List<Integer> list = dao.find( "select u.id from User u where u.status=? and u.registerDate<=?", new Object[] {UserStatus.NEW, timeLine}); Integer[] array = new Integer[list.size()]; for (int i = 0; i < list.size(); i++) { array[i] = list.get(i); } return dao.deleteByIdArray(array); }
public boolean activeUser(String email, String code) { List<User> userList = (List<User>) dao.find("from User u where u.email=? and u.code=?", new Object[] {email, code}); if (userList.size() != 0) { User user = userList.get(0); user.setStatus(UserStatus.REGULAR); dao.saveOrUpdate(user); return true; } else { if (email != null && !email.equals("")) { List<User> newUserList = (List<User>) dao.find( "from User u where u.email=? and u.status=?", new Object[] {email, UserStatus.NEW}); if (newUserList.size() != 0) { User newUser = userList.get(0); dao.delete(newUser); } } return false; } }