手机登录修改

This commit is contained in:
hupeng
2023-10-18 11:46:02 +08:00
parent d0c7d3e527
commit 2bc4abbc3d
3 changed files with 20 additions and 11 deletions

View File

@ -17,7 +17,7 @@ public class RegParam {
@ApiModelProperty(value = "手机号码") @ApiModelProperty(value = "手机号码")
private String account; private String account;
@NotBlank(message = "验证码必填") //@NotBlank(message = "验证码必填")
@ApiModelProperty(value = "验证码") @ApiModelProperty(value = "验证码")
private String captcha; private String captcha;

View File

@ -195,8 +195,13 @@ public class AuthController {
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery()
.eq(YxUser::getUsername,loginVerifyParam.getAccount())); .eq(YxUser::getUsername,loginVerifyParam.getAccount()));
//用户不存在自动创建
if(yxUser == null) { 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()); String token = JwtToken.makeToken(yxUser.getUid(),yxUser.getUsername());
@ -277,14 +282,14 @@ public class AuthController {
@PostMapping("/register/verify") @PostMapping("/register/verify")
@ApiOperation(value = "短信验证码发送", notes = "短信验证码发送") @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送")
public ApiResult<String> verify(@Validated @RequestBody VerityParam param) { public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() // YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery()
.eq(YxUser::getPhone,param.getPhone()),false); // .eq(YxUser::getPhone,param.getPhone()),false);
if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(yxUser)) { // if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(yxUser)) {
return ApiResult.fail("手机号已注册"); // return ApiResult.fail("手机号已注册");
} // }
if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(yxUser)) { // if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(yxUser)) {
return ApiResult.fail("账号不存在"); // return ApiResult.fail("账号不存在");
} // }
String codeKey = "code_" + param.getPhone(); String codeKey = "code_" + param.getPhone();
if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) { if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) {
return ApiResult.fail("10分钟内有效:" + redisUtil.get(codeKey).toString()); return ApiResult.fail("10分钟内有效:" + redisUtil.get(codeKey).toString());

View File

@ -165,6 +165,8 @@ public class AuthService {
.phone(phoneNoInfo.getPhoneNumber()) .phone(phoneNoInfo.getPhoneNumber())
.addIp(ip) .addIp(ip)
.lastIp(ip) .lastIp(ip)
.nickname(phoneNoInfo.getPhoneNumber())
.avatar(ShopConstants.YSHOP_DEFAULT_AVATAR)
.userType(AppFromEnum.ROUNTINE.getValue()) .userType(AppFromEnum.ROUNTINE.getValue())
.build(); .build();
@ -293,7 +295,7 @@ public class AuthService {
* @param param RegDTO * @param param RegDTO
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void register(RegParam param) { public YxUser register(RegParam param) {
String account = param.getAccount(); String account = param.getAccount();
String ip = IpUtil.getRequestIp(); String ip = IpUtil.getRequestIp();
@ -319,6 +321,8 @@ public class AuthService {
} }
} }
return user;
} }