Quellcode durchsuchen

增加退出登录接口

yaobo vor 7 Jahren
Ursprung
Commit
2f39346df6
1 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen
  1. 18 1
      src/main/java/cn/efunbox/audio/controller/AdminController.java

+ 18 - 1
src/main/java/cn/efunbox/audio/controller/AdminController.java

@@ -75,6 +75,14 @@ public class AdminController {
         return;
     }
 
+    @RequestMapping(value = "/logout" ,method = RequestMethod.POST)
+    public void Logout(HttpServletRequest request, HttpServletResponse response){
+        String id = request.getHeader("id");
+        ClearRedis(Long.valueOf(id));
+        HttpUtil.responseOk(request, response);
+        return;
+    }
+
 //    @RequestMapping(value = "/register", method = RequestMethod.POST)
 //    public void Insert(HttpServletRequest request, HttpServletResponse response){
 //        String name = request.getParameter("name");
@@ -195,6 +203,15 @@ public class AdminController {
      */
     public void SaveRedis(Admin admin){
         ValueOperations valueOperations = stringRedisTemplate.opsForValue();
-        valueOperations.set(Consts.REDIS_ADMIN+admin.getId(), admin.getToken(), tokenExpire*3600, TimeUnit.SECONDS);
+        valueOperations.set(Consts.REDIS_ADMIN + admin.getId(), admin.getToken(), tokenExpire * 3600, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 将token从redis中清除
+     * @param idAdmin
+     */
+    public void ClearRedis(Long idAdmin){
+        ValueOperations valueOperations = stringRedisTemplate.opsForValue();
+        valueOperations.set(Consts.REDIS_ADMIN+idAdmin, "", tokenExpire*3600, TimeUnit.SECONDS);
     }
 }