@RequestMapping( path = "/login", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) public Map<String, Object> login( @RequestParam String username, @RequestParam String password, HttpServletRequest request) { User user = aclService.authenticate(username, password); if (null == user) return MessageUtils.fail("login failed"); SessionUtils.saveUser(user, request); return MessageUtils.success("login with user " + user.toString()); }
@RequestMapping(path = "/check_user", produces = MediaType.APPLICATION_JSON_VALUE) public Map<String, Object> check(HttpServletRequest request) { User user = SessionUtils.getUser(request); if (null == user) return MessageUtils.fail("user not login"); Map<String, Object> m = MessageUtils.success("user login"); Map<String, Object> u = new HashMap<>(); u.put("username", user.getUsername()); u.put("id", user.getId()); u.put("role", user.getRole()); m.put("user", u); return m; }
@RequestMapping(path = "/init_data") public Map<String, Object> initData() { Map<String, Object> m = null; Student stu = new Student(); stu.setUsername("liu"); stu.setPassword("pass"); userService.saveUser(stu); return MessageUtils.success("added student " + stu); }
@RequestMapping(path = "/logout", produces = MediaType.APPLICATION_JSON_VALUE) public Map<String, Object> logout(HttpServletRequest request) { HttpSession session = request.getSession(); if (null != session) session.invalidate(); return MessageUtils.success("logout"); }