/** * @param User * @return @Description:检测用户名的唯一性 */ @ResponseBody @RequestMapping("/checkUserNameExsits") public String checkUserNameExsits(User User) { try { User param = new User(); param.setUsername(User.getUsername()); List<User> list = this.userService.getAll(param); if (StringUtils.isNotBlank(User.getId())) { User u = this.userService.getUserById(User.getId()); if (u != null && u.getUsername().equals(User.getUsername())) { return "0"; } else { if (list != null && list.size() > 0) { return "1"; } } } else { if (list != null && list.size() > 0) { return "1"; } } } catch (Exception e) { e.printStackTrace(); logger.debug("UserController-checkUserNameExsits:" + e.getMessage()); } return "0"; }
// 对外提供的登录接口 这个方法暂时不用 public LoginVo login( String username, String password, String companyId, String ip, String systemSn) throws Exception { LoginVo vo = new LoginVo(); SessionMap sessionMap = new SessionMap(); // 1:查询到用户对象 User user = login(username, password); if (user != null) { vo.setLoginUser(user); vo.setSid(user.getId()); sessionMap.put(PrivilegeConstant.LOGIN_USER, JsonUtils.toJson(user)); Set<ACL> acls = (Set<ACL>) aclService.getAclsByUserId(user.getId()); sessionMap.put(PrivilegeConstant.LOGIN_USER_ACLS, JsonUtils.toJson(acls)); ICSystem icSystem = icSystemDao.getICSystemBySn(systemSn); if (icSystem != null) { List<Module> modules = moduleService.getTreeModuleBySystemIdAndAcls(acls, icSystem.getId()); vo.setModules(modules); } else { throw new PrivilegeException("系统标示找不到"); } // 插入登录日志 LoginLog loginLog = new LoginLog(ip, user.getId(), user.getUsername(), user.getRealName(), "登录"); loginLogService.insertLoginLog(loginLog); CacheEntity ce = new CacheEntity(user.getId(), sessionMap, PrivilegeConstant.SESSION_OUT_TIME); CacheListHandler.addCache(user.getId(), ce); // redisClientTemplate.setex(user.getId(), // PrivilegeConstant.SESSION_OUT_TIME, // JsonUtils.toJson(sessionMap)); } return vo; }
/** * @param oldpwd * @param newpwd * @param request * @return @Description:重置密码 */ @ResponseBody @RequestMapping("/rePassword") public String rePassword(String oldpwd, String newpwd, HttpServletRequest request) { SimpleReturnVo vo; User user = WebUtils.getLoginUser(request); String password = MD5Util.getMD5String(PrivilegeConstant.USER_PASSWORD_FRONT + oldpwd); if (!password.equals(user.getPassword())) { vo = new SimpleReturnVo(this.FAIL, "原密码不正确!"); return JsonUtils.toJson(vo); } try { User newUser = new User(); newUser.setId(user.getId()); password = MD5Util.getMD5String(PrivilegeConstant.USER_PASSWORD_FRONT + newpwd); newUser.setPassword(password); this.userService.singleUpdateUser(newUser); vo = new SimpleReturnVo(this.SUCCESS, "成功"); } catch (Exception e) { e.printStackTrace(); logger.debug("UserController-rePassword:"******"异常错误!"); } return JsonUtils.toJson(vo); }
@Override public void updateUser(User user) throws Exception { userDao.updateUser(user); this.userSystemDao.delByUserId(user.getId()); String systemIds = user.getSystemIds(); if (StringUtils.isNotBlank(systemIds)) { String[] syses = systemIds.split(","); for (String sys : syses) { UserSystem userSystem = new UserSystem(); userSystem.setSystemId(sys); userSystem.setId(UUIDGenerator.generate()); userSystem.setUserId(user.getId()); this.userSystemDao.insertUserSystem(userSystem); } } }
@Override public PagerModel<User> getPagerModel(User user, Query query) throws Exception { PagerModel<User> pm = userDao.getPagerModel(user, query); for (User ur : pm.getDatas()) { List<Role> list = this.userRoleDao.getRolesByUserId(ur.getId()); if (list != null && list.size() > 0) { StringBuffer s = new StringBuffer(); for (int i = 0, len = list.size(); i < len; i++) { if (i != 0) { s.append(","); } s.append(list.get(i).getName()); } ur.setRoles(s.toString()); } } return pm; }