public void checkExist() { PrintWriter pw = null; try { this.getResponse().setCharacterEncoding("UTF-8"); pw = this.getResponse().getWriter(); String result; User user = new User(); user.setUserName(userName); user = userServices.queryUserByBean(user); if (user != null) { result = "exist"; } else { result = "ok"; } pw.write(result); } catch (Exception e) { e.printStackTrace(); } pw.flush(); pw.close(); }
public void saveNewUser() { PrintWriter pw = null; try { this.getResponse().setCharacterEncoding("UTF-8"); pw = this.getResponse().getWriter(); String result; User user = new User(); user.setUserName(userName); user = userServices.queryUserByBean(user); if (user != null) { result = "exist"; } else { user = new User(); user.setUserName(userName); user.setPassword(MD5Utils.strToMD5(password)); user.setRealName(realName); user.setCreateTime(DateUtils.getNowTime()); userServices.insertUser(user); result = "success"; } pw.write(result); } catch (Exception e) { e.printStackTrace(); } pw.flush(); pw.close(); }
public void deleteUser() { PrintWriter pw = null; try { this.getResponse().setCharacterEncoding("UTF-8"); pw = this.getResponse().getWriter(); User userInSession = (User) this.getRequest().getSession().getAttribute("userInSession"); String result; User user = new User(); user.setId(id); user = userServices.queryUserByBean(user); int size = userServices.countUserByCreatePid(id); if (user != null) { if (userInSession.getUserName().equals(user.getUserName())) { result = "self"; } else if (("admin").equals(user.getUserName())) { result = "admin"; } else { this.userRoleServices.deleteUserRoleByUser(user); if (size > 0) { this.userServices.hideUser(user); } else { this.userServices.deleteUser(user); } result = "success"; } } else { result = "fail"; } pw.write(result); } catch (Exception e) { e.printStackTrace(); } pw.flush(); pw.close(); }