|
|
@ -17,6 +17,7 @@ import com.luoo.user.util.IOSTokenUtils;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
import controller.BaseController;
|
|
|
|
import controller.BaseController;
|
|
|
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.RequestFrequencyTypeEnum;
|
|
|
|
import enums.RequestFrequencyTypeEnum;
|
|
|
|
import enums.UserStatusEnum;
|
|
|
|
import enums.UserStatusEnum;
|
|
|
|
import exception.BizException;
|
|
|
|
import exception.BizException;
|
|
|
@ -54,161 +55,161 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
@Api(tags = "LoginController")
|
|
|
|
@Api(tags = "LoginController")
|
|
|
|
public class LoginController extends BaseController {
|
|
|
|
public class LoginController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
|
|
|
|
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
|
|
|
|
.asList(new CountryCodeDTO("中国", "+86"));
|
|
|
|
.asList(new CountryCodeDTO("中国", "+86"));
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private WeChatAouth2Service weChatAouth2Service;
|
|
|
|
private WeChatAouth2Service weChatAouth2Service;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${download.url}")
|
|
|
|
@Value("${download.url}")
|
|
|
|
private String downloadUrl;
|
|
|
|
private String downloadUrl;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 更新好友粉丝数和用户关注数
|
|
|
|
* 更新好友粉丝数和用户关注数
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@PutMapping("/{userid}/{friendid}/{x}")
|
|
|
|
@PutMapping("/{userid}/{friendid}/{x}")
|
|
|
|
public void updatefanscountandfollowcount(@PathVariable String userid,
|
|
|
|
public void updatefanscountandfollowcount(@PathVariable String userid,
|
|
|
|
@PathVariable String friendid,
|
|
|
|
@PathVariable String friendid,
|
|
|
|
@PathVariable int x) {
|
|
|
|
@PathVariable int x) {
|
|
|
|
userInfoService.updatefanscountandfollowcount(x, userid, friendid);
|
|
|
|
userInfoService.updatefanscountandfollowcount(x, userid, friendid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 发送短信验证码
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟,一个手机号一天内最多发送20个请求")
|
|
|
|
|
|
|
|
@PostMapping("/sendsms")
|
|
|
|
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
|
|
|
|
|
|
|
|
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
|
|
|
|
|
|
|
|
if (sendSmsReq.getMobile().equals("18812345678")) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 测试用手机号
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
|
|
|
|
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
|
|
|
|
String redisImageCheckCodeKey =
|
|
|
|
|
|
|
|
Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
|
|
|
|
|
|
|
|
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
|
|
|
|
|
|
|
|
if (StringTools.isEmpty(redisImageCheckCode)) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!redisImageCheckCode.equalsIgnoreCase(sendSmsReq.getImageCheckCode())) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
redisTemplate.delete(redisImageCheckCodeKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
userInfoService.sendSms(sendSmsReq.getDeviceId(), sendSmsReq.getMobile());
|
|
|
|
/**
|
|
|
|
return Result.success();
|
|
|
|
* 发送短信验证码
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟,一个手机号一天内最多发送20个请求")
|
|
|
|
@ApiOperation(value = "2.登录/注册", notes = "成功后返回authorization")
|
|
|
|
@PostMapping("/sendsms")
|
|
|
|
@PostMapping("/appLogin")
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
|
|
|
|
public Result<String> appLogin(HttpServletRequest request,
|
|
|
|
if (sendSmsReq.getMobile().equals("18812345678")) {
|
|
|
|
@VerifyParam LoginReq loginReq) {
|
|
|
|
/**
|
|
|
|
if ("18812345678".equals(loginReq.getMobile())) {
|
|
|
|
* 测试用手机号
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
*/
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
return Result.success();
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
}
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
String token = userInfoService.loginOrRegister(loginUserInfo);
|
|
|
|
String redisImageCheckCodeKey =
|
|
|
|
return Result.success(token);
|
|
|
|
Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
|
|
|
|
}
|
|
|
|
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
if (StringTools.isEmpty(redisImageCheckCode)) {
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId();
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
|
|
|
|
}
|
|
|
|
if (StringTools.isEmpty(redisMobileCheckCode)) {
|
|
|
|
if (!redisImageCheckCode.equalsIgnoreCase(sendSmsReq.getImageCheckCode())) {
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
redisTemplate.delete(redisImageCheckCodeKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userInfoService.sendSms(sendSmsReq.getDeviceId(), sendSmsReq.getMobile());
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
@ApiOperation(value = "2.登录/注册", notes = "成功后返回authorization")
|
|
|
|
|
|
|
|
@PostMapping("/appLogin")
|
|
|
|
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
|
|
|
|
public Result<String> appLogin(HttpServletRequest request,
|
|
|
|
|
|
|
|
@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 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
@ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
@PostMapping("/appleIdLogin")
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
public Result<String> appleIdLogin(HttpServletRequest request,
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
@VerifyParam AppleLoginReq appleLoginReq) {
|
|
|
|
String token = userInfoService.loginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
redisTemplate.delete(redisMobileCheckCodeKey);
|
|
|
|
// 无手机号和验证码
|
|
|
|
return Result.success(token);
|
|
|
|
String identityToken = appleLoginReq.getIdentityToken();
|
|
|
|
}
|
|
|
|
// 解码后的消息体
|
|
|
|
|
|
|
|
JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
|
|
|
|
@ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
|
|
|
|
Boolean success;
|
|
|
|
@PostMapping("/appleIdLogin")
|
|
|
|
try {
|
|
|
|
public Result<String> appleIdLogin(HttpServletRequest request,
|
|
|
|
success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
|
|
|
|
@VerifyParam AppleLoginReq appleLoginReq) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
// 无手机号和验证码
|
|
|
|
|
|
|
|
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);
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
if (!success) {
|
|
|
|
// TODO 校验token失败具体操作
|
|
|
|
// TODO 校验token失败具体操作
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
// loginUserInfo.setMobile(appleLoginReq.getMobile());
|
|
|
|
// loginUserInfo.setMobile(appleLoginReq.getMobile());
|
|
|
|
loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
|
|
|
|
loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
|
|
|
|
loginUserInfo.setAppleEmail(playloadObj.get("email") + "");
|
|
|
|
loginUserInfo.setAppleEmail(playloadObj.get("email") + "");
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
loginUserInfo.setLastLoginIp(getIpAddr(request));
|
|
|
|
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
|
|
|
|
String token = userInfoService.appleLoginOrRegister(loginUserInfo);
|
|
|
|
String token = userInfoService.appleLoginOrRegister(loginUserInfo);
|
|
|
|
|
|
|
|
|
|
|
|
return Result.success(token);
|
|
|
|
return Result.success(token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
|
|
|
|
|
|
|
|
@PostMapping("/wxIdLogin")
|
|
|
|
|
|
|
|
public Result<String> wxIdLogin(HttpServletRequest request,
|
|
|
|
|
|
|
|
@VerifyParam WeChatLoginReq weChatLoginReq) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有手机号,是首次微信登录时绑定流程
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
|
|
|
|
|
|
|
|
//得到缓存中的验证码
|
|
|
|
|
|
|
|
String redisMobileCheckCodeKey =
|
|
|
|
|
|
|
|
Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
|
|
|
|
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue()
|
|
|
|
|
|
|
|
.get(redisMobileCheckCodeKey);
|
|
|
|
|
|
|
|
if (StringTools.isEmpty(redisMobileCheckCode)) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return weChatAouth2Service.register(weChatLoginReq, getIpAddr(request));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录,如果有记录登录正常执行,如果无记录,返回状态到上面绑定手机号流程
|
|
|
|
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
|
|
|
|
return weChatAouth2Service.login(weChatLoginReq, getIpAddr(request));
|
|
|
|
@PostMapping("/wxIdLogin")
|
|
|
|
|
|
|
|
public Result<String> wxIdLogin(HttpServletRequest request,
|
|
|
|
|
|
|
|
@VerifyParam WeChatLoginReq weChatLoginReq) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有手机号,是首次微信登录时绑定流程
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
|
|
|
|
|
|
|
|
//得到缓存中的验证码
|
|
|
|
|
|
|
|
String redisMobileCheckCodeKey =
|
|
|
|
|
|
|
|
Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
|
|
|
|
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue()
|
|
|
|
|
|
|
|
.get(redisMobileCheckCodeKey);
|
|
|
|
|
|
|
|
if (StringTools.isEmpty(redisMobileCheckCode)) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return weChatAouth2Service.register(weChatLoginReq, getIpAddr(request));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录,如果有记录登录正常执行,如果无记录,返回状态到上面绑定手机号流程
|
|
|
|
|
|
|
|
return weChatAouth2Service.login(weChatLoginReq, getIpAddr(request));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @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)
|
|
|
@ -296,173 +297,177 @@ public class LoginController extends BaseController {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* authorization 续期
|
|
|
|
* authorization 续期
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "3.token续期", notes = "有效期7天")
|
|
|
|
@ApiOperation(value = "3.token续期", notes = "有效期7天")
|
|
|
|
@PostMapping("/autoLogin")
|
|
|
|
@PostMapping("/autoLogin")
|
|
|
|
@GlobalInterceptor
|
|
|
|
@GlobalInterceptor
|
|
|
|
public Result<String> autoLogin(HttpServletRequest request,
|
|
|
|
public Result<String> autoLogin(HttpServletRequest request,
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
@VerifyParam TokenRefreshReq tokenRefreshReq) {
|
|
|
|
@VerifyParam TokenRefreshReq tokenRefreshReq) {
|
|
|
|
return Result.success(userInfoService.autoLogin(authorization, tokenRefreshReq.getDeviceId(),
|
|
|
|
return Result.success(userInfoService.autoLogin(authorization, tokenRefreshReq.getDeviceId(),
|
|
|
|
tokenRefreshReq.getDeviceBrand(), getIpAddr(request)));
|
|
|
|
tokenRefreshReq.getDeviceBrand(), getIpAddr(request)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取图行验证码
|
|
|
|
* 获取图行验证码
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后,获取图形验证码,有效期10分钟")
|
|
|
|
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后,获取图形验证码,有效期10分钟")
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
|
|
|
|
@GetMapping("/imageCheckCode/{deviceId}")
|
|
|
|
@GetMapping("/imageCheckCode/{deviceId}")
|
|
|
|
@GlobalInterceptor
|
|
|
|
@GlobalInterceptor
|
|
|
|
public void imageCheckCode(HttpServletResponse response,
|
|
|
|
public void imageCheckCode(HttpServletResponse response,
|
|
|
|
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
|
|
|
|
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
|
|
|
|
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
|
|
|
|
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
|
|
|
|
response.setHeader("Pragma", "no-cache");
|
|
|
|
response.setHeader("Pragma", "no-cache");
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
response.setDateHeader("Expires", 0);
|
|
|
|
response.setDateHeader("Expires", 0);
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
|
String code = vCode.getCode();
|
|
|
|
String code = vCode.getCode();
|
|
|
|
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
|
|
|
|
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
|
|
|
|
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
|
|
|
|
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
|
|
|
|
vCode.write(response.getOutputStream());
|
|
|
|
vCode.write(response.getOutputStream());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 4.1获取图形验证码Base64
|
|
|
|
* 4.1获取图形验证码Base64
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "4.1获取图形验证码Base64", notes = "4.三次短信验证失败后,获取图形验证码Base64,有效期10分钟")
|
|
|
|
@ApiOperation(value = "4.1获取图形验证码Base64", notes = "4.三次短信验证失败后,获取图形验证码Base64,有效期10分钟")
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
|
|
|
|
@GetMapping("/imageCheckCodeBase64/{deviceId}")
|
|
|
|
@GetMapping("/imageCheckCodeBase64/{deviceId}")
|
|
|
|
@GlobalInterceptor
|
|
|
|
@GlobalInterceptor
|
|
|
|
public Result<String> imageCheckCodeBase64(HttpServletResponse response,
|
|
|
|
public Result<String> imageCheckCodeBase64(HttpServletResponse response,
|
|
|
|
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
|
|
|
|
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
|
|
|
|
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
|
|
|
|
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
|
|
|
|
response.setHeader("Pragma", "no-cache");
|
|
|
|
response.setHeader("Pragma", "no-cache");
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
response.setDateHeader("Expires", 0);
|
|
|
|
response.setDateHeader("Expires", 0);
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
|
String code = vCode.getCode();
|
|
|
|
String code = vCode.getCode();
|
|
|
|
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
|
|
|
|
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
|
|
|
|
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
|
|
|
|
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
vCode.write(bos);
|
|
|
|
vCode.write(bos);
|
|
|
|
return Result.success(Base64.getEncoder().encodeToString(bos.toByteArray()));
|
|
|
|
return Result.success(Base64.getEncoder().encodeToString(bos.toByteArray()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取支持的手机号国家码
|
|
|
|
* 获取支持的手机号国家码
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'")
|
|
|
|
@ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'")
|
|
|
|
@GetMapping("/supportedCountryCode")
|
|
|
|
@GetMapping("/supportedCountryCode")
|
|
|
|
public Result<List<CountryCodeDTO>> getSupportedCountryCode() {
|
|
|
|
public Result<List<CountryCodeDTO>> getSupportedCountryCode() {
|
|
|
|
return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES);
|
|
|
|
return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 退出登录
|
|
|
|
* 退出登录
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param authorization
|
|
|
|
* @param authorization
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "6.退出登录")
|
|
|
|
@ApiOperation(value = "6.退出登录")
|
|
|
|
@PostMapping("/logout")
|
|
|
|
@PostMapping("/logout")
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
public Result<Void> logout(
|
|
|
|
public Result<Void> logout(
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization) {
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization) {
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 通过用户名/密码登录
|
|
|
|
* 通过用户名/密码登录
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return 登录结果
|
|
|
|
* @return 登录结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "7.通过用户名/密码登录")
|
|
|
|
@ApiOperation(value = "7.通过用户名/密码登录")
|
|
|
|
@PostMapping("/login/username")
|
|
|
|
@PostMapping("/login/username")
|
|
|
|
public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) {
|
|
|
|
public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) {
|
|
|
|
String userName = userNameLoginDto.getUserName();
|
|
|
|
String userName = userNameLoginDto.getUserName();
|
|
|
|
String password = userNameLoginDto.getPassword();
|
|
|
|
String password = userNameLoginDto.getPassword();
|
|
|
|
UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password);
|
|
|
|
UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password);
|
|
|
|
if (ObjectUtils.notEqual(UserStatusEnum.ENABLE.getStatus(), userInfo.getStatus())) {
|
|
|
|
if (ObjectUtils.notEqual(UserStatusEnum.ENABLE.getStatus(), userInfo.getStatus())) {
|
|
|
|
// 用户状态错误
|
|
|
|
// 用户状态错误
|
|
|
|
throw new BizException(ErrorConstants.USER_STATUS_ERROR);
|
|
|
|
throw new BizException(ErrorConstants.USER_STATUS_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userInfo != null) {
|
|
|
|
|
|
|
|
//生成token
|
|
|
|
|
|
|
|
String token = jwtUtil.createJWT(userInfo.getId(), userInfo.getUserName(), "artist", "");
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("token", token);
|
|
|
|
|
|
|
|
map.put("roles", "artist");
|
|
|
|
|
|
|
|
map.put("name", userInfo.getUserName());
|
|
|
|
|
|
|
|
return Result.success(map);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "8.修改密码")
|
|
|
|
|
|
|
|
@PostMapping("/changePassword")
|
|
|
|
|
|
|
|
public Result<Void> changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) {
|
|
|
|
|
|
|
|
userInfoService.changePassword(changePasswordDto.getUserName(),
|
|
|
|
|
|
|
|
changePasswordDto.getPassword());
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userInfo != null) {
|
|
|
|
|
|
|
|
//生成token
|
|
|
|
@ApiOperation(value = "9.1.获取UUID", notes = "获取UUID")
|
|
|
|
String token = jwtUtil.createJWT(userInfo.getId(), userInfo.getUserName(), "artist", "");
|
|
|
|
@GetMapping(value = "/uuid")
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
public Result<String> getUuid() {
|
|
|
|
map.put("token", token);
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
map.put("roles", "artist");
|
|
|
|
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
|
|
|
|
map.put("name", userInfo.getUserName());
|
|
|
|
return Result.success(uuid);
|
|
|
|
return Result.success(map);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0-未完成 1-已扫码 other-token")
|
|
|
|
@ApiOperation(value = "8.修改密码")
|
|
|
|
@GetMapping(value = "/check/qr")
|
|
|
|
@PostMapping("/changePassword")
|
|
|
|
public Result<String> getCountryCode(String uuid) {
|
|
|
|
public Result<Void> changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) {
|
|
|
|
return Result.success(redisTemplate.opsForValue().get(uuid).toString());
|
|
|
|
userInfoService.changePassword(changePasswordDto.getUserName(),
|
|
|
|
}
|
|
|
|
changePasswordDto.getPassword());
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
|
|
|
|
}
|
|
|
|
@GetMapping(value = "/getLoginQr")
|
|
|
|
|
|
|
|
public Result<String> createCodeImg(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
@ApiOperation(value = "9.1.获取UUID", notes = "获取UUID")
|
|
|
|
String uuid) {
|
|
|
|
@GetMapping(value = "/uuid")
|
|
|
|
|
|
|
|
public Result<String> getUuid() {
|
|
|
|
try {
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
|
|
|
|
Object o = redisTemplate.opsForValue().get(uuid);
|
|
|
|
return Result.success(uuid);
|
|
|
|
if (o == null) {
|
|
|
|
}
|
|
|
|
throw new BizException("二维码失效!");
|
|
|
|
|
|
|
|
}
|
|
|
|
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0-未完成 1-已扫码 other-token")
|
|
|
|
if (!String.valueOf(o).equals("0")) {
|
|
|
|
@GetMapping(value = "/check/qr")
|
|
|
|
throw new BizException("登录认证已完成");
|
|
|
|
public Result<String> getCountryCode(String uuid) {
|
|
|
|
}
|
|
|
|
return Result.success(redisTemplate.opsForValue().get(uuid).toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
|
|
|
|
}
|
|
|
|
@GetMapping(value = "/getLoginQr")
|
|
|
|
|
|
|
|
public Result<String> createCodeImg(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
log.info(downloadUrl);
|
|
|
|
String uuid) {
|
|
|
|
return Result.success(downloadUrl + "?code=" + uuid);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object o = redisTemplate.opsForValue().get(uuid);
|
|
|
|
|
|
|
|
if (o == null) {
|
|
|
|
|
|
|
|
throw new BizException("二维码失效!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!String.valueOf(o).equals("0")) {
|
|
|
|
|
|
|
|
throw new BizException("登录认证已完成");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info(downloadUrl);
|
|
|
|
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等,仅APP用户可用")
|
|
|
|
return Result.success(downloadUrl + "?code=" + uuid);
|
|
|
|
@PostMapping(value = "/scanOrConfirm")
|
|
|
|
}
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等")
|
|
|
|
@ApiImplicitParam(name = "authorization", value = "Authorization", required = true),
|
|
|
|
@PostMapping(value = "/scanOrConfirm")
|
|
|
|
@ApiImplicitParam(name = "token", value = "扫码获得的code", required = true),
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "token", value = "扫码获得的code", required = true),
|
|
|
|
@ApiImplicitParam(name = "type", value = "type 1-扫码 2-确认", required = true)})
|
|
|
|
@ApiImplicitParam(name = "userId", value = "用户id", required = true),
|
|
|
|
public Result<Void> scanOrConfirm(
|
|
|
|
@ApiImplicitParam(name = "type", value = "type 1-扫码 2-确认", required = true)})
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
|
|
|
public Result<Void> scanOrConfirm(@RequestParam("token") String token,
|
|
|
|
@RequestParam("token") String token,
|
|
|
|
@RequestParam("userId") String userId,
|
|
|
|
@RequestParam("type") Integer type) {
|
|
|
|
@RequestParam("type") Integer type) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
userInfoService.scan(userId, token, type);
|
|
|
|
userInfoService.scan(userLoginDto.getUserId(), token, type);
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|