1.clean code

main
Gary 9 months ago
parent 894311fb31
commit faf9d32036

@ -122,12 +122,12 @@ public class LoginController extends BaseController {
if (!redisMobileCheckCode.equals(mobileCheckCode)) { if (!redisMobileCheckCode.equals(mobileCheckCode)) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
} }
UserInfo userInfo = new UserInfo(); UserInfo loginUserInfo = new UserInfo();
userInfo.setMobile(mobile); loginUserInfo.setMobile(mobile);
userInfo.setLastUseDeviceId(deviceId); loginUserInfo.setLastUseDeviceId(deviceId);
userInfo.setLastUseDeviceBrand(deviceBrand); loginUserInfo.setLastUseDeviceBrand(deviceBrand);
userInfo.setLastLoginIp(getIpAddr(request)); loginUserInfo.setLastLoginIp(getIpAddr(request));
return Result.success(userInfoService.loginOrRegister(userInfo)); return Result.success(userInfoService.loginOrRegister(loginUserInfo));
} finally { } finally {
redisTemplate.delete(redisMobileCheckCodeKey); redisTemplate.delete(redisMobileCheckCodeKey);
} }

@ -193,30 +193,30 @@ public class UserInfoService {
return userInfoDao.countByNickName(nickName); return userInfoDao.countByNickName(nickName);
} }
public String loginOrRegister(UserInfo userInfo) { public String loginOrRegister(UserInfo loginUserInfo) {
UserInfo user = userInfoDao.findByMobile(userInfo.getMobile()); UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
if (null == user) { if (null == userInfo) {
user = userInfo; userInfo = loginUserInfo;
user.setId(String.valueOf(idWorker.nextId())); userInfo.setId(String.valueOf(idWorker.nextId()));
user.setNickName("雀乐-" + NickNameUtil.getRandomNickName()); userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
Date curDate = new Date(); Date curDate = new Date();
user.setJoinTime(curDate); userInfo.setJoinTime(curDate);
user.setLastLoginTime(curDate); userInfo.setLastLoginTime(curDate);
user.setStatus(UserStatusEnum.ENABLE.getStatus()); userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
user.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
user.setSignature(Constants.DEFAULT_USER_SIGNATURE); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
} else { } else {
user.setLastUseDeviceId(userInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
user.setLastUseDeviceBrand(userInfo.getLastUseDeviceBrand()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
user.setLastLoginIp(userInfo.getLastLoginIp()); userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
} }
if (!UserStatusEnum.ENABLE.getStatus().equals(user.getStatus())) { if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
return null; return null;
} }
user.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(user); userInfoDao.save(userInfo);
return Constants.TOKEN_PREFIX 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<UserInfo> orderByField(List<String> idList) { public List<UserInfo> orderByField(List<String> idList) {

Loading…
Cancel
Save