diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index fb2b6b5..827e171 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -447,8 +447,6 @@ public class MyController extends BaseController { } - - @ApiOperation(value = "12 注销账号", notes = "注销账号") @PostMapping ("/logOff") public Result logOff(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam LogoffReq logoffReq) { @@ -474,6 +472,32 @@ public class MyController extends BaseController { } + @ApiOperation(value = "13 绑定手机号", notes = "绑定手机号") + @PostMapping ("/bindMobile") + public Result bindMobile(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam LoginReq loginReq) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + // 得到缓存中的验证码 + String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId(); + String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey); + if (StringTools.isEmpty(redisMobileCheckCode)) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); + } + if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); + } + + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setMobile(loginReq.getMobile()); + userInfoService.update(userInfo); + return Result.success(); + } + + private Integer getIndex(UserInfo u) { return Integer.valueOf(Arrays.stream(u.getBadges().split(",")).filter(s->s.startsWith(String.valueOf(UserBadgeEnum.CONTRIBUTOR.getCode()))).findFirst().get().split("_")[1]); diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index 910d49d..27ba394 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -327,4 +327,9 @@ public class UserInfoService { return userInfoDao.getThanks(); } + + public void bindMobile(UserInfo userInfo){ + userInfoDao.save(userInfo); + } + }