|
|
@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.luoo.user.dto.request.AppleLoginReq;
|
|
|
|
import com.luoo.user.dto.request.AppleLoginReq;
|
|
|
|
import com.luoo.user.util.IOSTokenUtils;
|
|
|
|
import com.luoo.user.util.IOSTokenUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@ -82,6 +83,12 @@ public class LoginController extends BaseController {
|
|
|
|
@PostMapping("/sendsms")
|
|
|
|
@PostMapping("/sendsms")
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
|
|
|
|
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
|
|
|
|
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
|
|
|
|
|
|
|
|
if(sendSmsReq.getMobile().equals("18812345678")){
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 测试用手机号
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
|
|
|
|
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
|
|
|
|
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
|
|
|
@ -104,6 +111,15 @@ public class LoginController extends BaseController {
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
public Result<String> appLogin(HttpServletRequest request,
|
|
|
|
public Result<String> appLogin(HttpServletRequest request,
|
|
|
|
@VerifyParam LoginReq loginReq) {
|
|
|
|
@VerifyParam LoginReq loginReq) {
|
|
|
|
|
|
|
|
if("18812345678".equals(loginReq.getMobile())) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
|
|
|
}
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId();
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId();
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
|
|
|
@ -122,35 +138,127 @@ public class LoginController extends BaseController {
|
|
|
|
redisTemplate.delete(redisMobileCheckCodeKey);
|
|
|
|
redisTemplate.delete(redisMobileCheckCodeKey);
|
|
|
|
return Result.success(token);
|
|
|
|
return Result.success(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
|
|
|
|
@ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
|
|
|
|
@PostMapping("/appleIdLogin")
|
|
|
|
@PostMapping("/appleIdLogin")
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
public Result<String> appleIdLogin(HttpServletRequest request,@RequestBody AppleLoginReq appleLoginReq) {
|
|
|
|
public Result<String> appleIdLogin(HttpServletRequest request,@VerifyParam AppleLoginReq appleLoginReq) {
|
|
|
|
|
|
|
|
|
|
|
|
String identityToken = appleLoginReq.getIdentityToken();
|
|
|
|
|
|
|
|
// 解码后的消息体
|
|
|
|
// 无手机号和验证码
|
|
|
|
JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
|
|
|
|
String identityToken = appleLoginReq.getIdentityToken();
|
|
|
|
Boolean success;
|
|
|
|
// 解码后的消息体
|
|
|
|
try {
|
|
|
|
JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
|
|
|
|
success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
|
|
|
|
Boolean success;
|
|
|
|
} catch (Exception e) {
|
|
|
|
try {
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
|
|
|
// TODO 校验token失败具体操作
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
// loginUserInfo.setMobile(appleLoginReq.getMobile());
|
|
|
|
|
|
|
|
loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
|
|
|
|
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
|
|
|
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
|
|
|
|
|
|
|
|
String token = userInfoService.appleLoginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
|
|
|
// TODO 校验token失败具体操作
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
|
|
|
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
|
|
|
|
loginUserInfo.setLastUseDeviceBrand("iPhone");
|
|
|
|
|
|
|
|
String token = userInfoService.appleLoginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
|
|
|
|
|
|
|
|
// @PostMapping("/appleIdLogin")
|
|
|
|
|
|
|
|
// @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
|
|
|
|
// public Result<String> appleIdLogin(HttpServletRequest request,@VerifyParam AppleLoginReq appleLoginReq) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if("18812345678".equals(appleLoginReq.getMobile())) {
|
|
|
|
|
|
|
|
// UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
// loginUserInfo.setMobile(appleLoginReq.getMobile());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
|
|
|
// String token = userInfoService.loginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
// return Result.success(token);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 如果有手机号和验证码
|
|
|
|
|
|
|
|
// if(StringUtils.isNotEmpty(appleLoginReq.getMobile()) && StringUtils.isNotEmpty(appleLoginReq.getMobileCheckCode())) {
|
|
|
|
|
|
|
|
// // 得到缓存中的验证码
|
|
|
|
|
|
|
|
// String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + appleLoginReq.getDeviceId();
|
|
|
|
|
|
|
|
// String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
|
|
|
|
|
|
|
|
// if (StringTools.isEmpty(redisMobileCheckCode)) {
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!redisMobileCheckCode.equals(appleLoginReq.getMobileCheckCode())) {
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// String identityToken = appleLoginReq.getIdentityToken();
|
|
|
|
|
|
|
|
// // 解码后的消息体
|
|
|
|
|
|
|
|
// JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
|
|
|
|
|
|
|
|
// Boolean success;
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
|
|
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
|
|
|
|
//// throw new RuntimeException(e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!success) {
|
|
|
|
|
|
|
|
// // TODO 校验token失败具体操作
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
// loginUserInfo.setMobile(appleLoginReq.getMobile());
|
|
|
|
|
|
|
|
// loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
|
|
|
// loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
|
|
|
|
|
|
|
|
// String token = userInfoService.loginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
// redisTemplate.delete(redisMobileCheckCodeKey);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return Result.success(token);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 无手机号和验证码
|
|
|
|
|
|
|
|
// String identityToken = appleLoginReq.getIdentityToken();
|
|
|
|
|
|
|
|
// // 解码后的消息体
|
|
|
|
|
|
|
|
// JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
|
|
|
|
|
|
|
|
// Boolean success;
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
|
|
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
|
|
|
|
//// throw new RuntimeException(e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!success) {
|
|
|
|
|
|
|
|
// // TODO 校验token失败具体操作
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
// loginUserInfo.setMobile(appleLoginReq.getMobile());
|
|
|
|
|
|
|
|
// loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
|
|
|
|
// loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
|
|
|
|
// loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
|
|
|
|
|
|
|
|
// String token = userInfoService.appleLoginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if("未注册".equals(token)) {
|
|
|
|
|
|
|
|
// return Result.failed(StatusCode.APPLEID_MOBILE_UNBINDED);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return Result.success(token);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|