lyq пре 3 месеци
родитељ
комит
41105e8b23

+ 2 - 0
src/main/java/com/sooka/common/constant/CmsConst.java

@@ -37,4 +37,6 @@ public class CmsConst {
     public static final String SEARCH_TPL= "search";
 
     public static final String TOPIC_TPL= "topic";
+
+    public static final String LOGIN_USER = "LoginUser";
 }

+ 16 - 2
src/main/java/com/sooka/module/web/cms/IndexController.java

@@ -27,6 +27,8 @@ import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
+import static com.sooka.common.constant.CmsConst.LOGIN_USER;
+
 /**
  * Description:前台首页
  *
@@ -93,7 +95,7 @@ public class IndexController {
 
     /*网站首页*/
     @GetMapping
-    public ModelAndView index(@RequestParam(value = "keyword",required = false) String keyword){
+    public ModelAndView index(@RequestParam(value = "keyword",required = false) String keyword, HttpServletRequest request){
         String domain = ControllerUtil.getDomain();
         log.debug("通过域名访问网站首页[{}]",domain);
         TCmsSite site = siteService.findByDomain(domain);
@@ -103,7 +105,13 @@ public class IndexController {
         if(!StrUtil.isBlank(keyword)) {
             return new ModelAndView( "forward:/"+sitePrefix+"/search");
         }
-        return new ModelAndView( "forward:/"+sitePrefix+"/"+site.getSiteId());
+        ModelAndView modelAndView = new ModelAndView( "forward:/"+sitePrefix+"/"+site.getSiteId());
+        if (request.getSession().getAttribute(LOGIN_USER) == null) {
+            modelAndView.addObject("btnId", "login");
+        } else {
+            modelAndView.addObject("btnId", "exit");
+        }
+        return modelAndView;
     }
 
     @GetMapping("/login")
@@ -113,6 +121,12 @@ public class IndexController {
         return modelAndView;
     }
 
+    @GetMapping("/exit")
+    public ModelAndView exit(HttpServletRequest request){
+        request.getSession().removeAttribute(LOGIN_USER);
+        return index(null, request);
+    }
+
     @GetMapping("/register")
     public ModelAndView register(){
         ModelAndView modelAndView=new ModelAndView("www/tuiyijunren/register");

+ 4 - 1
src/main/java/com/sooka/module/web/system/service/impl/CmsUserServiceImpl.java

@@ -19,6 +19,8 @@ import javax.servlet.http.HttpSession;
 import java.util.Date;
 import java.util.Map;
 
+import static com.sooka.common.constant.CmsConst.LOGIN_USER;
+
 /**
  * Description:前台用户控制器
  *
@@ -75,7 +77,8 @@ public class CmsUserServiceImpl implements CmsUserService {
             /*更新用户的登陆信息*/
             userMapper.updateByPrimaryKey(user);
             /*设置session*/
-            session.setAttribute("cms-login-user", user);
+            session.setAttribute(LOGIN_USER, user);
+            session.setMaxInactiveInterval(30 * 60);
             result.put("success", true);
             result.put("message", "登录成功!");
         } catch (Exception e) {

+ 5 - 2
src/main/resources/templates/www/tuiyijunren/include/header-index.html

@@ -18,8 +18,11 @@
 <!--头部开始-->
 <div class="header">
     <div class="top_btn">
-        <span>
-            <a href="login">登录</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="/register">注册</a>
+        <span id="login" style="display: none">
+            <a href="login">登录</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="register">注册</a>
+        </span>
+        <span id="exit" style="display: none">
+            <a href="exit">退出</a>
         </span>
     </div>
     <div class="wid1200"><img src="${resPath}/tuiyijunren/images/twjr_logo.png"/>

+ 1 - 0
src/main/resources/templates/www/tuiyijunren/index.html

@@ -555,6 +555,7 @@
         buttons: true
     });
     $(function () {
+        $(${btnId}).show();
         //	列表切换
         $('.news_tab_list').eq(0).show().siblings('.news_tab_list').hide();
         $('.news_tab_tit a').hover(function () {