Browse Source

1.注册添加创建时间字段
2.规范用户登录注册接口地址

Linyt 1 year ago
parent
commit
50ed021a53

+ 54 - 0
java/src/main/java/boot/modules/common/controller/CommonController.java

@@ -1,12 +1,24 @@
 package boot.modules.common.controller;
 
+import boot.common.constant.SchoolConstant;
+import boot.common.enums.SmsTypeEnum;
+import boot.common.respond.ApiCode;
 import boot.common.respond.ApiResult;
+import boot.common.utils.RedisUtils;
 import boot.common.utils.UploadUtils;
+import boot.modules.user.param.VerityParam;
+import boot.modules.user.pojo.User;
+import boot.modules.user.service.UserService;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
@@ -18,6 +30,8 @@ import java.util.List;
 @RestController
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
 public class CommonController {
+    private final UserService userService;
+    private final RedisUtils redisUtil;
     /**
      * 图片上传
      */
@@ -32,4 +46,44 @@ public class CommonController {
         //返回访问的文件路径
         return ApiResult.ok(url);
     }
+
+    @PostMapping("/register/verify")
+    @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送")
+    public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
+        User shopUser = userService.getOne(Wrappers.<User>lambdaQuery()
+                .eq(User::getPhone, param.getPhone()), false);
+        if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(shopUser)) {
+            return ApiResult.fail(ApiCode.FAIL,"手机号已注册");
+        }
+        if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(shopUser)) {
+            return ApiResult.fail(ApiCode.FAIL,"账号不存在");
+        }
+        String codeKey = "code_" + param.getPhone();
+        if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) {
+            return ApiResult.fail(ApiCode.FAIL,"10分钟内有效:" + redisUtil.get(codeKey).toString());
+        }
+        String code = RandomUtil.randomNumbers(SchoolConstant.SCHOOL_SMS_SIZE);
+
+        //redis存储
+        redisUtil.set(codeKey, code, SchoolConstant.SCHOOL_SMS_REDIS_TIME);
+
+//        String enable = redisUtil.getY("sms_enable");
+        Boolean enable = false;
+//        if (SchoolEnum.ENABLE_2.getValue().toString().equals(enable)) {
+        return ApiResult.ok(code);
+//        }
+
+        //发送阿里云短信
+//        JSONObject json = new JSONObject();
+//        json.put("code", code);
+//        try {
+//            SmsUtils.sendSms(param.getPhone(), json.toJSONString());
+//        } catch (ClientException e) {
+//            redisUtil.del(codeKey);
+//            e.printStackTrace();
+//            return ApiResult.ok("发送失败:" + e.getErrMsg());
+//        }
+//        return ApiResult.ok("发送成功,请注意查收");
+
+    }
 }

+ 2 - 38
java/src/main/java/boot/modules/user/controller/UserController.java

@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
@@ -41,6 +42,7 @@ import java.util.Map;
 @RestController
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
 @Api(value = "认证模块", tags = "认证")
+@RequestMapping("/user")
 public class UserController {
     private final UserService userService;
     private final RedisUtils redisUtil;
@@ -103,45 +105,7 @@ public class UserController {
     }
 
 
-    @PostMapping("/register/verify")
-    @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送")
-    public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
-        User shopUser = userService.getOne(Wrappers.<User>lambdaQuery()
-                .eq(User::getPhone, param.getPhone()), false);
-        if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(shopUser)) {
-            return ApiResult.fail(ApiCode.FAIL,"手机号已注册");
-        }
-        if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(shopUser)) {
-            return ApiResult.fail(ApiCode.FAIL,"账号不存在");
-        }
-        String codeKey = "code_" + param.getPhone();
-        if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) {
-            return ApiResult.fail(ApiCode.FAIL,"10分钟内有效:" + redisUtil.get(codeKey).toString());
-        }
-        String code = RandomUtil.randomNumbers(SchoolConstant.SCHOOL_SMS_SIZE);
-
-        //redis存储
-        redisUtil.set(codeKey, code, SchoolConstant.SCHOOL_SMS_REDIS_TIME);
-
-//        String enable = redisUtil.getY("sms_enable");
-        Boolean enable = false;
-//        if (SchoolEnum.ENABLE_2.getValue().toString().equals(enable)) {
-        return ApiResult.ok(code);
-//        }
-
-        //发送阿里云短信
-//        JSONObject json = new JSONObject();
-//        json.put("code", code);
-//        try {
-//            SmsUtils.sendSms(param.getPhone(), json.toJSONString());
-//        } catch (ClientException e) {
-//            redisUtil.del(codeKey);
-//            e.printStackTrace();
-//            return ApiResult.ok("发送失败:" + e.getErrMsg());
-//        }
-//        return ApiResult.ok("发送成功,请注意查收");
 
-    }
     @AuthCheck
     @ApiOperation(value = "退出登录", notes = "退出登录")
     @PostMapping(value = "/auth/logout")

+ 2 - 0
java/src/main/java/boot/modules/user/service/impl/AuthService.java

@@ -58,6 +58,7 @@ public class AuthService {
                 .avatar(null)
                 .addIp(ip)
                 .lastIp(ip)
+                .createTime(new Date())
                 .build();
 
         userService.save(user);
@@ -77,6 +78,7 @@ public class AuthService {
                 .password(SecureUtil.md5(param.getPassword()))
                 .phone(account)
                 .avatarId(null)
+                .createTime(new Date())
                 .build();
 
         manageService.save(user);

BIN
java/target/classes/boot/modules/user/service/impl/AuthService.class