From 94824893b36be287747af35902eea499c7acfa12 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期六, 15 六月 2024 19:21:26 +0800
Subject: [PATCH] 代码

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java |   61 ++++++++++++++++--------------
 1 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
index 7cac3e2..9e3043c 100644
--- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
+++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
@@ -29,7 +29,6 @@
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -359,24 +358,26 @@
         }
         return R.ok();
     }
+
     @PostMapping("/getUserInfoParent")
     @ApiOperation(value = "获取用户信息", tags = {"家长端-获取用户信息"})
     public R<TUser> getUserInfo() {
         LoginUserParent loginUser1 = tokenService.getLoginUser1();
-        if (loginUser1!=null){
+        if (loginUser1 != null) {
             TUser byId = userService.getById(loginUser1.getUserid());
-            if (byId.getVipEndTime() == null){
+            if (byId.getVipEndTime() == null) {
                 byId.setIsVip(0);
-            }else if (byId.getVipEndTime().after(new Date())){
+            } else if (byId.getVipEndTime().after(new Date())) {
                 byId.setIsVip(1);
-            }else{
+            } else {
                 byId.setIsVip(0);
             }
             return R.ok(byId);
-        }else{
+        } else {
             return R.tokenError("登录失效");
         }
     }
+
     @PostMapping("/parentPage")
     @ApiOperation(value = "平板", tags = {"启动页"})
     public R<String> parentPage() {
@@ -460,26 +461,26 @@
                 .eq("phone", phone));
         if (tUser1 != null) {
             if (tUser1.getState() == 2) {
-                throw new GlobalException("登录失败,您的账号已被冻结!");
+                return R.freeze("登录失败,您的账号已被冻结!");
             }
         } else {
             // 手机验证码校验
-            if (!phoneCode.equals("123456")){
-            Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
+            if (!phoneCode.equals("123456")) {
+                Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
                 if (null == redisPhoneCode) {
-                    throw new GlobalException("登录失败,手机验证码已过期!");
+                    return R.errorCode("登录失败,手机验证码无效!");
                 } else {
                     // redis 验证码的value 为 code:时间戳
                     String rCodeAndTime = String.valueOf(redisPhoneCode);
                     String rCode = rCodeAndTime.split(":")[0];
                     if (!rCode.equalsIgnoreCase(phoneCode)) {
-                        throw new GlobalException("登录失败,手机验证码输入有误!");
+                        return R.errorCode("登录失败,手机验证码无效!");
                     } else {
                         tUser1 = getUser(phone);
                         userService.save(tUser1);
                     }
                 }
-            }else{
+            } else {
                 tUser1 = getUser(phone);
                 userService.save(tUser1);
             }
@@ -529,7 +530,7 @@
                         userService.save(user);
                     }
                 }
-            }else{
+            } else {
                 user = getUser(phone);
                 userService.save(user);
             }
@@ -548,6 +549,7 @@
 
     /**
      * 学生端退出登录
+     *
      * @param request 请求信息
      */
     @PostMapping("/logoutStudy")
@@ -590,7 +592,7 @@
     @ApiImplicitParams({
             @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
     })
-    public R<?> sendPhoneCode(@RequestParam String phone) {
+    public R<?> sendPhoneCode(@RequestParam String phone) throws Exception {
         return userService.phoneCode(phone) ? R.ok() : R.fail();
     }
 
@@ -602,7 +604,7 @@
     public R<TSysSet> shareInfo() {
         // 分享信息
         TSysSet data = managementClient.shareInfo().getData();
-        if (tokenService.getLoginUserStudy() == null){
+        if (tokenService.getLoginUserStudy() == null) {
             return R.tokenError("登录失效");
         }
         Integer userid = tokenService.getLoginUserStudy().getUserid();
@@ -631,7 +633,7 @@
     public R<TSysSet> shareInfoParent() {
         // 分享信息
         TSysSet data = managementClient.shareInfo().getData();
-        if (tokenService.getLoginUser1() == null){
+        if (tokenService.getLoginUser1() == null) {
             return R.tokenError("登录失效");
         }
         Integer userid = tokenService.getLoginUser1().getUserid();
@@ -651,6 +653,7 @@
         }
         return R.ok(data);
     }
+
     /**
      * 获取用户信息
      *
@@ -686,7 +689,7 @@
             @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
     })
     public R<String> logout(HttpServletRequest request) {
-        if (tokenService.getLoginUser1() == null){
+        if (tokenService.getLoginUser1() == null) {
             return R.tokenError("登录失效");
         }
         String token = SecurityUtils.getToken(request);
@@ -707,8 +710,8 @@
             @ApiImplicitParam(name = "headImg", value = "头像 改什么就只传什么"),
             @ApiImplicitParam(name = "phoneCode", value = "手机验证码,修改手机号的时候传"),
     })
-    public R<String> updateUserInfo(String name, String phone, String headImg,String phoneCode) {
-        if (tokenService.getLoginUser1() == null){
+    public R<String> updateUserInfo(String name, String phone, String headImg, String phoneCode) {
+        if (tokenService.getLoginUser1() == null) {
             return R.tokenError("登录失效");
         }
         Integer userid = tokenService.getLoginUser1().getUserid();
@@ -730,16 +733,18 @@
             byId.setPhone(phone);
         }
         // 手机验证码校验
-        if (!phoneCode.equals("123456")){
-            Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
-            if (null == redisPhoneCode) {
-                return R.errorCode("手机验证码无效");
-            } else {
-                // redis 验证码的value 为 code:时间戳
-                String rCodeAndTime = String.valueOf(redisPhoneCode);
-                String rCode = rCodeAndTime.split(":")[0];
-                if (!rCode.equalsIgnoreCase(phoneCode)) {
+        if (StringUtils.hasLength(phoneCode)){
+            if (!phoneCode.equals("123456")) {
+                Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
+                if (null == redisPhoneCode) {
                     return R.errorCode("手机验证码无效");
+                } else {
+                    // redis 验证码的value 为 code:时间戳
+                    String rCodeAndTime = String.valueOf(redisPhoneCode);
+                    String rCode = rCodeAndTime.split(":")[0];
+                    if (!rCode.equalsIgnoreCase(phoneCode)) {
+                        return R.errorCode("手机验证码无效");
+                    }
                 }
             }
         }

--
Gitblit v1.7.1