浏览代码

增加退出登录接口

yaobo 7 年之前
父节点
当前提交
2f39346df6
共有 1 个文件被更改,包括 18 次插入1 次删除
  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);
     }
 }