1、用户注册、登录。
2、搜索用户添加好友。
3、查看好友申请列表,同意或拒绝好友请求。
4、成为好友后单人一对一聊天。
5、可创建群聊进行聊天。
除了上述基本的聊天功能外,还有:消息提醒方式设置(可设置是否d框、是否声音提醒等,提供可选六种新消息提示音)、聊天记录清空、拉黑好友、删除好友、解散群聊、隐身、在线状态设置、好友上下线提醒等等,功能非常的全。
重点:聊天信息中可发送文字、图片、文件、视频、音乐、表情包等。
后台:1、后台菜单、角色、管理员的管理。
2、后台聊天信息、在线用户等统计。
3、后台日志管理、数据备份等。
4、用户管理:用户信息查看、状态冻结等。
5、群聊管理:成员查看、移除成员、解散群聊等。
6、消息管理:消息详细信息跟踪查看等。
系统控制器:
@RequestMapping("/system") @Controller public class SystemController { @Autowired private OperaterLogService operaterLogService; @Autowired private UserService userService; @Autowired private DatabaseBakService databaseBakService; private Logger log = LoggerFactory.getLogger(SystemController.class); @RequestMapping(value="/login",method=RequestMethod.GET) public String login(Model model){ return "admin/system/login"; } @RequestMapping(value="/login",method=RequestMethod.POST) @ResponseBody public Result后台用户管理控制器:login(HttpServletRequest request,User user,String cpacha){ if(user == null){ return Result.error(CodeMsg.DATA_ERROR); } //用统一验证实体方法验证是否合法 CodeMsg validate = ValidateEntityUtil.validate(user); if(validate.getCode() != CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } //表示实体信息合法,开始验证验证码是否为空 if(StringUtils.isEmpty(cpacha)){ return Result.error(CodeMsg.CPACHA_EMPTY); } //说明验证码不为空,从session里获取验证码 Object attribute = request.getSession().getAttribute("admin_login"); if(attribute == null){ return Result.error(CodeMsg.SESSION_EXPIRED); } //表示session未失效,进一步判断用户填写的验证码是否正确 if(!cpacha.equalsIgnoreCase(attribute.toString())){ return Result.error(CodeMsg.CPACHA_ERROR); } //表示验证码正确,开始查询数据库,检验密码是否正确 User findByUsername = userService.findByUsername(user.getUsername()); //判断是否为空 if(findByUsername == null){ return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST); } //表示用户存在,进一步对比密码是否正确 if(!findByUsername.getPassword().equals(user.getPassword())){ return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR); } //表示密码正确,接下来判断用户状态是否可用 if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){ return Result.error(CodeMsg.ADMIN_USER_UNABLE); } //检查用户所属角色状态是否可用 if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){ return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE); } //检查用户所属角色的权限是否存在 if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){ return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY); } //检查一切符合,可以登录,将用户信息存放至session request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, findByUsername); //销毁session中的验证码 request.getSession().setAttribute("admin_login", null); //将登陆记录写入日志库 operaterLogService.add("用户【"+user.getUsername()+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!"); log.info("用户成功登录,user = " + findByUsername); return Result.success(true); } @RequestMapping(value="/face_login",method=RequestMethod.POST) @ResponseBody public Result faceLogin(@RequestParam(name="username",required=true)String username,@RequestParam(name="face",required=true)String face){ User user = userService.findByUsername(username); //判断是否为空 if(user == null){ return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST); } if(StringUtils.isEmpty(user.getFace())){ return Result.error(CodeMsg.ADMIN_USER_FACE_EMPTY); } //判断用户状态是否可用 if(user.getStatus() == User.ADMIN_USER_STATUS_UNABLE){ return Result.error(CodeMsg.ADMIN_USER_UNABLE); } //检查用户所属角色状态是否可用 if(user.getRole() == null || user.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){ return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE); } //检查用户所属角色的权限是否存在 if(user.getRole().getAuthorities() == null || user.getRole().getAuthorities().size() == 0){ return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY); } //此处调用百度api接口对比两张人脸相似度 String faceMatch = BaiduApi.faceMatch(user.getFace(), face); log.info(faceMatch); JSonObject parseObject = JSONObject.parseObject(faceMatch); if(parseObject.getIntValue("error_code") != 0){ CodeMsg codeMsg = CodeMsg.DATA_ERROR; codeMsg.setMsg(parseObject.getString("error_msg")); return Result.error(codeMsg); } //此处判断人脸可信度 JSonObject result = parseObject.getJSonObject("result"); if(result.getBigDecimal("score").compareTo(new BigDecimal(80)) < 0){ return Result.error(CodeMsg.ADMIN_USER_FACE_NOT_MATCH); } //检查一切符合,可以登录,将用户信息存放至session SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, user); //将登陆记录写入日志库 operaterLogService.add("用户【"+user.getUsername()+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】人脸识别登录系统!"); log.info("用户成功登录,user = " + user); return Result.success(true); } @RequestMapping(value="/face_login_check",method=RequestMethod.POST) @ResponseBody public Result faceLoginCheck(@RequestParam(name="username",required=true)String username){ User user = userService.findByUsername(username); if(user == null){ return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST); } if(StringUtils.isEmpty(user.getFace())){ return Result.error(CodeMsg.ADMIN_USER_FACE_EMPTY); } return Result.success(true); } @RequestMapping(value="/index") public String index(Model model){ model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10)); model.addAttribute("userTotal", userService.total()); model.addAttribute("operatorLogTotal", operaterLogService.total()); model.addAttribute("databaseBackupTotal", databaseBakService.total()); model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount); return "admin/system/index"; } @RequestMapping(value="/logout") public String logout(){ User loginedUser = SessionUtil.getLoginedUser(); if(loginedUser != null){ SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null); } return "redirect:login"; } @RequestMapping(value="/no_right") public String noRight(){ return "admin/system/no_right"; } @RequestMapping(value="/update_userinfo",method=RequestMethod.GET) public String updateUserInfo(){ return "admin/system/update_userinfo"; } @RequestMapping(value="/update_userinfo",method=RequestMethod.POST) public String updateUserInfo(User user){ User loginedUser = SessionUtil.getLoginedUser(); loginedUser.setEmail(user.getEmail()); loginedUser.setMobile(user.getMobile()); loginedUser.setHeadPic(user.getHeadPic()); //首先保存到数据库 userService.save(loginedUser); //更新session里的值 SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser); return "redirect:update_userinfo"; } @RequestMapping(value="/update_pwd",method=RequestMethod.GET) public String updatePwd(){ return "admin/system/update_pwd"; } @RequestMapping(value="/update_pwd",method=RequestMethod.POST) @ResponseBody public Result updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd, @RequestParam(name="newPwd",required=true)String newPwd ){ User loginedUser = SessionUtil.getLoginedUser(); if(!loginedUser.getPassword().equals(oldPwd)){ return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR); } if(StringUtils.isEmpty(newPwd)){ return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY); } loginedUser.setPassword(newPwd); //保存数据库 userService.save(loginedUser); //更新session SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser); return Result.success(true); } @RequestMapping(value="/operator_log_list") public String operatorLogList(Model model,OperaterLog operaterLog,PageBean pageBean){ model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean)); model.addAttribute("operator", operaterLog.getOperator()); model.addAttribute("title", "日志列表"); return "admin/system/operator_log_list"; } @RequestMapping(value="/delete_operator_log",method=RequestMethod.POST) @ResponseBody public Result delete(String ids){ if(!StringUtils.isEmpty(ids)){ String[] splitIds = ids.split(","); for(String id : splitIds){ operaterLogService.delete(Long.valueOf(id)); } } return Result.success(true); } @RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST) @ResponseBody public Result deleteAll(){ operaterLogService.deleteAll(); return Result.success(true); } }
@RequestMapping("/user") @Controller public class UserController { @Autowired private UserService userService; @Autowired private RoleService roleService; @Autowired private OperaterLogService operaterLogService; @RequestMapping(value="/list") public String list(Model model,User user,PageBean后台角色管理控制器:pageBean){ model.addAttribute("title", "用户列表"); model.addAttribute("username", user.getUsername()); model.addAttribute("pageBean", userService.findList(user, pageBean)); return "admin/user/list"; } @RequestMapping(value="/add",method=RequestMethod.GET) public String add(Model model){ model.addAttribute("roles", roleService.findAll()); return "admin/user/add"; } @RequestMapping(value="/add_face",method=RequestMethod.GET) public String addFace(Model model,@RequestParam(name="id",required=true)Long id){ model.addAttribute("user", userService.find(id)); return "admin/user/add_face"; } @RequestMapping(value="/add_face",method=RequestMethod.POST) @ResponseBody public Result addFace(User user){ //判断是否有人脸信息 if(StringUtils.isEmpty(user.getFace())){ return Result.error(CodeMsg.ADMIN_USE_ADD_FACE_ERROR); } User existUser = userService.find(user.getId()); if(existUser == null){ return Result.error(CodeMsg.ADMIN_USE_NO_EXIST); } String faceDetect = BaiduApi.faceDetect(user.getFace(), "base64"); JSonObject parseObject = JSONObject.parseObject(faceDetect); if(parseObject.getIntValue("error_code") != 0){ CodeMsg codeMsg = CodeMsg.DATA_ERROR; codeMsg.setMsg(parseObject.getString("error_msg")); return Result.error(codeMsg); } //此处判断人脸可信度 JSonObject result = parseObject.getJSonObject("result"); if(result.getIntValue("face_num") > 1){ return Result.error(CodeMsg.ADMIN_USE_FACE_NUMBER_ERROR); } JSonArray faceList = result.getJSonArray("face_list"); JSonObject face = faceList.getJSonObject(0); if(face.getFloatValue("face_probability") < 0.8){ return Result.error(CodeMsg.ADMIN_USE_FACE_PROB_LOW); } existUser.setFace(user.getFace()); //到这说明一切符合条件,进行数据库新增 if(userService.save(existUser) == null){ return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR); } operaterLogService.add("录入用户人脸信息"); return Result.success(true); } @RequestMapping(value="/add",method=RequestMethod.POST) @ResponseBody public Result add(User user){ //用统一验证实体方法验证是否合法 CodeMsg validate = ValidateEntityUtil.validate(user); if(validate.getCode() != CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } if(user.getRole() == null || user.getRole().getId() == null){ return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY); } //判断用户名是否存在 if(userService.isExistUsername(user.getUsername(), 0l)){ return Result.error(CodeMsg.ADMIN_USERNAME_EXIST); } //到这说明一切符合条件,进行数据库新增 if(userService.save(user) == null){ return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR); } operaterLogService.add("添加用户,用户名:" + user.getUsername()); return Result.success(true); } @RequestMapping(value="/edit",method=RequestMethod.GET) public String edit(Model model,@RequestParam(name="id",required=true)Long id){ model.addAttribute("roles", roleService.findAll()); model.addAttribute("user", userService.find(id)); return "admin/user/edit"; } @RequestMapping(value="/edit",method=RequestMethod.POST) @ResponseBody public Result edit(User user){ //用统一验证实体方法验证是否合法 CodeMsg validate = ValidateEntityUtil.validate(user); if(validate.getCode() != CodeMsg.SUCCESS.getCode()){ return Result.error(validate); } if(user.getRole() == null || user.getRole().getId() == null){ return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY); } if(user.getId() == null || user.getId().longValue() <= 0){ return Result.error(CodeMsg.ADMIN_USE_NO_EXIST); } if(userService.isExistUsername(user.getUsername(), user.getId())){ return Result.error(CodeMsg.ADMIN_USERNAME_EXIST); } //到这说明一切符合条件,进行数据库保存 User findById = userService.find(user.getId()); //讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容 BeanUtils.copyProperties(user, findById, "id","createTime","updateTime"); if(userService.save(findById) == null){ return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR); } operaterLogService.add("编辑用户,用户名:" + user.getUsername()); return Result.success(true); } @RequestMapping(value="/delete",method=RequestMethod.POST) @ResponseBody public Result delete(@RequestParam(name="id",required=true)Long id){ try { userService.delete(id); } catch (Exception e) { return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR); } operaterLogService.add("添加用户,用户ID:" + id); return Result.success(true); } }
@RequestMapping("/role") @Controller public class RoleController { private Logger log = LoggerFactory.getLogger(RoleController.class); @Autowired private MenuService menuService; @Autowired private OperaterLogService operaterLogService; @Autowired private RoleService roleService; @RequestMapping(value="/list") public String list(Model model,Role role,PageBeanpageBean){ model.addAttribute("title", "角色列表"); model.addAttribute("name", role.getName()); model.addAttribute("pageBean", roleService.findByName(role, pageBean)); return "admin/role/list"; } @RequestMapping(value="/add",method=RequestMethod.GET) public String add(Model model){ List
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)