|
|
|
@ -103,23 +103,21 @@ public class LoginController extends BaseController {
|
|
|
|
|
@VerifyParam LoginReq loginReq) {
|
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId();
|
|
|
|
|
try {
|
|
|
|
|
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 loginUserInfo = new UserInfo();
|
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
return Result.success(userInfoService.loginOrRegister(loginUserInfo));
|
|
|
|
|
} finally {
|
|
|
|
|
redisTemplate.delete(redisMobileCheckCodeKey);
|
|
|
|
|
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 loginUserInfo = new UserInfo();
|
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
String token = userInfoService.loginOrRegister(loginUserInfo);
|
|
|
|
|
redisTemplate.delete(redisMobileCheckCodeKey);
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|