管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-09-30 fe25c74329239f48314e8c3f7f0d756f66f0768c
1
已修改3个文件
69 ■■■■■ 文件已修改
src/main/java/com/lf/server/helper/WebHelper.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/TokenService.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/templates/index.html 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/WebHelper.java
@@ -142,7 +142,7 @@
    public static void saveCookie(String cookieKey, String value, HttpServletResponse response) {
        Cookie cookie = new Cookie(cookieKey, value);
        // 设置cookie失效时间,单位为秒
        cookie.setMaxAge(240 * 60);
        cookie.setMaxAge(4 * 60 * 60);
        cookie.setHttpOnly(false);
        cookie.setPath("/");
        // cookie.setDomain("")
@@ -163,7 +163,6 @@
            for (Cookie c : cookies) {
                if (cookieKey.equalsIgnoreCase(c.getName())) {
                    c.setMaxAge(0);
                    break;
                }
            }
        }
src/main/java/com/lf/server/service/data/TokenService.java
@@ -159,15 +159,17 @@
        // 清除Cookie
        WebHelper.deleteCookie(StaticData.TOKEN_COOKIE_KEY, req);
        // 获取当前用户
        UsersEntity ue = getCurrentUser(req);
        if (ue == null) {
            return false;
        }
        // 清除缓存
        String tokenKey = RedisCacheKey.signTokenKey(token);
        redisService.delete(tokenKey);
        // 获取当前用户
        UsersEntity ue = getCurrentUser(req);
        if (te == null) {
            return false;
        }
        String userKey = RedisCacheKey.signUserKey(te.getToken());
        redisService.delete(userKey);
        // db,设置令牌过期
        te.setUpdateUser(ue.getId());
src/main/resources/templates/index.html
@@ -1,29 +1,41 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>Land系统-首页</title>
    <script>
        window.onload=function () {
            var url =  document.getElementById("url").value;
            if (url){
                window.location.href = url;
            }
  <meta charset="UTF-8">
  <title>管道基础大数据平台服务-首页</title>
  <script src="../js/jquery.min.js"></script>
  <script>
    window.onload = function () {
      var url = document.getElementById("url").value;
      if (url) {
        window.location.href = url;
      }
    }
    function logout() {
      $.get("logout", function (rs) {
        alert("code: " + rs.code + ", msg: " + rs.msg + ", result: " + rs.result);
        if (rs.code == 200) {
          location.href = location.origin + location.pathname;
        }
    </script>
      });
    }
  </script>
</head>
<body>
<h1>首页</h1>
<h2 th:text="${msg}"></h2>
<input id="url" type="hidden" th:value="${url}">
  <h1>首页</h1>
  <h2 th:text="${msg}"></h2>
  <input id="url" type="hidden" th:value="${url}">
<div shiro:guest="">
    <a th:href="@{/toLogin}">登录</a>
</div>
<br />
<div shiro:user>
    <a th:href="@{/logout}">注销</a>
</div>
  <div>
    <!--<a th:href="@{/toLogin}">登录</a>-->
    <a href="toLogin?service=http://192.168.20.106:12316/sign/toIndex">登录</a>
  </div>
  <br />
  <div>
    <!--<a th:href="@{/logout}">注销</a>-->
    <a href="javascript:void(0);" onclick="logout(); return false;">登出</a>
  </div>
</body>
</html>