Browse Source

短视频迁移-修正小程序登录校验过期返回值

chenhongzhou1 4 years ago
parent
commit
a2a39b0aba

+ 28 - 5
ymall/src/main/java/com/liangjian11/ymall/controller/video/VideoDoctorController.java

@@ -52,7 +52,7 @@ public class VideoDoctorController {
   @Value("${domain.ymall}")
   private String domain;
 
-  public Doctor getUser(HttpServletRequest request) {
+  public String getUser(HttpServletRequest request) {
     String userId = null;
     Cookie[] cookies = request.getCookies();
     if (cookies != null) {
@@ -65,11 +65,15 @@ public class VideoDoctorController {
       String token = RequestUtil.getRequest().getHeader("token");
       Document document = MongoDBUtil.queryVLoginTokenByToken(token);
       if (!Objects.isNull(document)) {
+        Date expirationDate = (Date) document.get("ExpirationDate");
+        if (expirationDate.compareTo(new Date()) <= 0) {
+          return "timeout";
+        }
         userId = (String) document.get("AccountId");
       }
     }
     if (!StringUtils.isEmpty(userId) && userAccountService.count(new QueryWrapper<UserAccount>().eq("id::varchar(100)", userId)) > 0) {
-      return doctorService.getDoctorByUserId(userId);
+      return userId;
     }
     return null;
   }
@@ -95,7 +99,14 @@ public class VideoDoctorController {
   @PostMapping("/UploadFileByDoctor")
   @ApiOperation(value = "上传视频归属到医生")
   public PageResultInfo UploadFileByDoctor(@ApiParam(value = "Video对象") @RequestBody DoctorVideoDTO dto) {
-    Doctor doctor = getUser(RequestUtil.getRequest());
+
+    String userId = getUser(RequestUtil.getRequest());
+    if (StringUtils.isEmpty(userId)) {
+      return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
+    }
+    Doctor doctor = doctorService.getDoctorByUserId(userId);
     if (Objects.isNull(doctor)) {
       return PageResultInfo.createFail("token为空或非医生用户登录");
     }
@@ -134,7 +145,13 @@ public class VideoDoctorController {
   @PostMapping("/GetMyVideoListByTranscoding")
   @ApiOperation(value = "获取医生作品列表 正在转码的列表")
   public PageResultInfo<List<Video>> GetMyVideoListByTranscoding(@ApiParam(value = "selectDTO对象") @RequestBody SelectDTO selectDTO) {
-    Doctor doctor = getUser(RequestUtil.getRequest());
+    String userId = getUser(RequestUtil.getRequest());
+    if (StringUtils.isEmpty(userId)) {
+      return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
+    }
+    Doctor doctor = doctorService.getDoctorByUserId(userId);
     if (Objects.isNull(doctor)) {
       return PageResultInfo.createFail("token为空或非医生用户登录");
     }
@@ -144,7 +161,13 @@ public class VideoDoctorController {
   @PostMapping("/GetMyVideoList")
   @ApiOperation(value = "获取医生作品列表")
   public PageResultInfo<List<Video>> GetMyVideoList(@ApiParam(value = "selectDTO对象") @RequestBody SelectDTO selectDTO) throws Exception {
-    Doctor doctor = getUser(RequestUtil.getRequest());
+    String userId = getUser(RequestUtil.getRequest());
+    if (StringUtils.isEmpty(userId)) {
+      return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
+    }
+    Doctor doctor = doctorService.getDoctorByUserId(userId);
     if (Objects.isNull(doctor)) {
       return PageResultInfo.createFail("token为空或非医生用户登录");
     }

+ 32 - 0
ymall/src/main/java/com/liangjian11/ymall/controller/video/VideoUserController.java

@@ -63,6 +63,10 @@ public class VideoUserController {
       String token = RequestUtil.getRequest().getHeader("token");
       Document document = MongoDBUtil.queryVLoginTokenByToken(token);
       if (!Objects.isNull(document)) {
+        Date expirationDate = (Date) document.get("ExpirationDate");
+        if (expirationDate.compareTo(new Date()) <= 0) {
+          return "timeout";
+        }
         userId = (String) document.get("AccountId");
       }
     }
@@ -79,6 +83,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.listVideoByHome(userId, selectDTO);
   }
@@ -97,6 +103,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.listVideoByHomePage(userId, selectDTO);
   }
@@ -109,6 +117,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (video.getId() != null) {
       video = videoService.getPlayInfo(video.getId(), userId);
@@ -123,6 +133,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (!StringUtils.isEmpty(selectDTO.getName())) {
       VideoHotsearch videoHotsearch = new VideoHotsearch();
@@ -146,6 +158,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.getDoctorVideoPage(userId, selectDTO);
   }
@@ -164,6 +178,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoUserAttentionService.getUserFollowList(userId, selectDTO);
   }
@@ -174,6 +190,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     return videoService.getMyLikeList(userId, selectDTO);
   }
@@ -185,6 +203,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     VideoStatisticsIntermediate oldPlayLog = videoStatisticsIntermediateService.getOne(new QueryWrapper<VideoStatisticsIntermediate>().eq("superior_id", video.getId()).eq("subordinate_id", userId));
     VideoStatisticsIntermediate playLog = null;
@@ -216,6 +236,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoLikeIntermediateService.count(new QueryWrapper<VideoLikeIntermediate>().eq("superior_id", video.getId()).eq("subordinate_id", userId)) > 0) {
       return PageResultInfo.createFail("保存失败,已有用户点赞记录");
@@ -244,6 +266,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoLikeIntermediateService.remove(new QueryWrapper<VideoLikeIntermediate>().eq("superior_id", video.getId()).eq("subordinate_id", userId))) {
       return PageResultInfo.createSuccess("用户取消点赞成功", null);
@@ -259,6 +283,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     VideoStatisticsIntermediate shareLog = new VideoStatisticsIntermediate();
     shareLog.setSuperiorID(video.getId());
@@ -283,6 +309,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoUserAttentionService.count(new QueryWrapper<VideoUserAttention>().eq("superior_id", doctor.getId()).eq("subordinate_id", userId)) > 0) {
       return PageResultInfo.createFail("保存失败,已有用户关注该医生记录");
@@ -310,6 +338,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoUserAttentionService.remove(new QueryWrapper<VideoUserAttention>().eq("superior_id", doctor.getId()).eq("subordinate_id", userId))) {
       return PageResultInfo.createSuccess("用户取关医生成功", null);
@@ -325,6 +355,8 @@ public class VideoUserController {
     String userId = getUser(RequestUtil.getRequest());
     if (StringUtils.isEmpty(userId)) {
       return PageResultInfo.createFail("token不能为空");
+    }else if("timeout".equals(userId)){
+      return PageResultInfo.createTimeOutFail("token/cookies过期,请重新请求授权");
     }
     if (videoCommentDTO.getVideoID() == null || StringUtils.isEmpty(videoCommentDTO.getContent())) {
       return PageResultInfo.createFail("缺少参数");

+ 13 - 0
ymall/src/main/java/com/liangjian11/ymall/utils/video/DTO/PageResultInfo.java

@@ -86,4 +86,17 @@ public class PageResultInfo<T> {
     return pageResultInfo;
   }
 
+
+  /**
+   * 创建token/cookies过期失败的消息提示
+   * @return
+   */
+  public static PageResultInfo createTimeOutFail(String message){
+    PageResultInfo pageResultInfo = new PageResultInfo();
+    pageResultInfo.setIsSuccess(false);
+    pageResultInfo.setResultCode(401);
+    pageResultInfo.setResultMsg(message);
+    return pageResultInfo;
+  }
+
 }