diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index 4ad2a20..926b4e2 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -122,12 +122,12 @@ public class LoginController extends BaseController { if (!redisMobileCheckCode.equals(mobileCheckCode)) { return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); } - UserInfo userInfo = new UserInfo(); - userInfo.setMobile(mobile); - userInfo.setLastUseDeviceId(deviceId); - userInfo.setLastUseDeviceBrand(deviceBrand); - userInfo.setLastLoginIp(getIpAddr(request)); - return Result.success(userInfoService.loginOrRegister(userInfo)); + UserInfo loginUserInfo = new UserInfo(); + loginUserInfo.setMobile(mobile); + loginUserInfo.setLastUseDeviceId(deviceId); + loginUserInfo.setLastUseDeviceBrand(deviceBrand); + loginUserInfo.setLastLoginIp(getIpAddr(request)); + return Result.success(userInfoService.loginOrRegister(loginUserInfo)); } finally { redisTemplate.delete(redisMobileCheckCodeKey); } 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 755075a..eeaaf60 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 @@ -193,30 +193,30 @@ public class UserInfoService { return userInfoDao.countByNickName(nickName); } - public String loginOrRegister(UserInfo userInfo) { - UserInfo user = userInfoDao.findByMobile(userInfo.getMobile()); - if (null == user) { - user = userInfo; - user.setId(String.valueOf(idWorker.nextId())); - user.setNickName("雀乐-" + NickNameUtil.getRandomNickName()); + public String loginOrRegister(UserInfo loginUserInfo) { + UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); + if (null == userInfo) { + userInfo = loginUserInfo; + userInfo.setId(String.valueOf(idWorker.nextId())); + userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName()); Date curDate = new Date(); - user.setJoinTime(curDate); - user.setLastLoginTime(curDate); - user.setStatus(UserStatusEnum.ENABLE.getStatus()); - user.setAvatar(Constants.DEFAULT_USER_AVATAR); - user.setSignature(Constants.DEFAULT_USER_SIGNATURE); + userInfo.setJoinTime(curDate); + userInfo.setLastLoginTime(curDate); + userInfo.setStatus(UserStatusEnum.ENABLE.getStatus()); + userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); + userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); } else { - user.setLastUseDeviceId(userInfo.getLastUseDeviceId()); - user.setLastUseDeviceBrand(userInfo.getLastUseDeviceBrand()); - user.setLastLoginIp(userInfo.getLastLoginIp()); + userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); + userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); + userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp()); } - if (!UserStatusEnum.ENABLE.getStatus().equals(user.getStatus())) { + if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) { return null; } - user.setLastLoginTime(new Date()); - userInfoDao.save(user); + userInfo.setLastLoginTime(new Date()); + userInfoDao.save(userInfo); return Constants.TOKEN_PREFIX - + jwtUtil.createJWT(user.getId(), user.getNickName(), Constants.TOKEN_ROLE_APP_USER, user.getAvatar()); + + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); } public List orderByField(List idList) {