From 2bc4abbc3dfcdb7b688edb716800dfd141b40d77 Mon Sep 17 00:00:00 2001 From: hupeng Date: Wed, 18 Oct 2023 11:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E7=99=BB=E5=BD=95=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yixiang/modules/auth/param/RegParam.java | 2 +- .../modules/auth/rest/AuthController.java | 23 +++++++++++-------- .../yixiang/modules/services/AuthService.java | 6 ++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/yshop-app/src/main/java/co/yixiang/modules/auth/param/RegParam.java b/yshop-app/src/main/java/co/yixiang/modules/auth/param/RegParam.java index cad7500d..e18de02a 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/auth/param/RegParam.java +++ b/yshop-app/src/main/java/co/yixiang/modules/auth/param/RegParam.java @@ -17,7 +17,7 @@ public class RegParam { @ApiModelProperty(value = "手机号码") private String account; - @NotBlank(message = "验证码必填") + //@NotBlank(message = "验证码必填") @ApiModelProperty(value = "验证码") private String captcha; diff --git a/yshop-app/src/main/java/co/yixiang/modules/auth/rest/AuthController.java b/yshop-app/src/main/java/co/yixiang/modules/auth/rest/AuthController.java index f98c8ef4..9513f817 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/auth/rest/AuthController.java +++ b/yshop-app/src/main/java/co/yixiang/modules/auth/rest/AuthController.java @@ -195,8 +195,13 @@ public class AuthController { YxUser yxUser = userService.getOne(Wrappers.lambdaQuery() .eq(YxUser::getUsername,loginVerifyParam.getAccount())); + //用户不存在自动创建 if(yxUser == null) { - throw new YshopException("账号不存在"); + RegParam param = new RegParam(); + param.setAccount(loginVerifyParam.getAccount()); + param.setPassword("yshop123456"); + param.setSpread(loginVerifyParam.getSpread()); + yxUser = authService.register(param); } String token = JwtToken.makeToken(yxUser.getUid(),yxUser.getUsername()); @@ -277,14 +282,14 @@ public class AuthController { @PostMapping("/register/verify") @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送") public ApiResult verify(@Validated @RequestBody VerityParam param) { - YxUser yxUser = userService.getOne(Wrappers.lambdaQuery() - .eq(YxUser::getPhone,param.getPhone()),false); - if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(yxUser)) { - return ApiResult.fail("手机号已注册"); - } - if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(yxUser)) { - return ApiResult.fail("账号不存在"); - } +// YxUser yxUser = userService.getOne(Wrappers.lambdaQuery() +// .eq(YxUser::getPhone,param.getPhone()),false); +// if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(yxUser)) { +// return ApiResult.fail("手机号已注册"); +// } +// if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(yxUser)) { +// return ApiResult.fail("账号不存在"); +// } String codeKey = "code_" + param.getPhone(); if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) { return ApiResult.fail("10分钟内有效:" + redisUtil.get(codeKey).toString()); diff --git a/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java b/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java index 72f798ff..18541514 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java +++ b/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java @@ -165,6 +165,8 @@ public class AuthService { .phone(phoneNoInfo.getPhoneNumber()) .addIp(ip) .lastIp(ip) + .nickname(phoneNoInfo.getPhoneNumber()) + .avatar(ShopConstants.YSHOP_DEFAULT_AVATAR) .userType(AppFromEnum.ROUNTINE.getValue()) .build(); @@ -293,7 +295,7 @@ public class AuthService { * @param param RegDTO */ @Transactional(rollbackFor = Exception.class) - public void register(RegParam param) { + public YxUser register(RegParam param) { String account = param.getAccount(); String ip = IpUtil.getRequestIp(); @@ -319,6 +321,8 @@ public class AuthService { } } + return user; + }