🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 请求接口如下 ``` @RequestMapping("login") @ResponseBody public DTO login(String userName,String password){ //密码加密 try{ UsernamePasswordToken token = new UsernamePasswordToken(userName,password); Subject subject = SecurityUtils.getSubject(); subject.login(token); Collection<Session> sessions = redisSessionDAO.getActiveSessions(); if (subject.isAuthenticated()) { for (Session session : sessions) { //方法一、当第二次登录时,给出提示“用户已登录”,停留在登录页面 if (userName.equals(session.getAttribute("USERNAME"))) { subject.logout(); msg="该账号已登录"; } } } if(StringUtils.isNotBlank(msg)){ subject.getSession().setTimeout(3600000L);//超时时间 User user = (User)subject.getPrincipal(); subject.getSession().setAttribute(Constant.USERSESSION,user ); subject.getSession().setAttribute(Constant.USERNAME, phone); } }catch (IncorrectCredentialsException ice) { msg="密码错误"; } catch (UnknownAccountException uae) { msg="该账号不存在"; } catch (LockedAccountException e) { msg="该账号已被冻结"; } catch (ExcessiveAttemptsException eae) { msg="服务器内部错误"; } catch (RuntimeException e) { e.printStackTrace(); } return new DTO(msg); } ```