|
|
|
@ -46,8 +46,9 @@ import util.StringTools;
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@RequestMapping("/user")
|
|
|
|
|
@Api(tags = "LoginController")
|
|
|
|
|
public class LoginController extends BaseController{
|
|
|
|
|
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES=Arrays.asList(new CountryCodeDTO("中国","+86"));
|
|
|
|
|
public class LoginController extends BaseController {
|
|
|
|
|
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
|
|
|
|
|
.asList(new CountryCodeDTO("中国", "+86"));
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
@ -71,30 +72,44 @@ public class LoginController extends BaseController{
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟,一个手机号一天内最多发送50个请求")
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86’", required = false, defaultValue="+86"),
|
|
|
|
|
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
|
|
|
|
|
@ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86’", required = false, defaultValue = "+86"),
|
|
|
|
|
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "imageCheckCode", value = "图形验证码", required = false) })
|
|
|
|
|
@PostMapping("/sendsms")
|
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50)
|
|
|
|
|
public Result<Void> sendSms(
|
|
|
|
|
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
|
|
|
|
|
@RequestParam(name="countryCode",defaultValue="+86") String countryCode,
|
|
|
|
|
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile) {
|
|
|
|
|
userInfoService.sendSms(deviceId,mobile);
|
|
|
|
|
public Result<Void> sendSms(@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
|
|
|
|
|
@RequestParam(name = "countryCode", defaultValue = "+86") String countryCode,
|
|
|
|
|
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
|
|
|
|
|
@VerifyParam(required = false) @RequestParam("imageCheckCode") String imageCheckCode) {
|
|
|
|
|
if (!StringTools.isEmpty(imageCheckCode)) {
|
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
|
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
|
|
|
|
|
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
|
|
|
|
|
if (StringTools.isEmpty(redisImageCheckCode)) {
|
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
|
}
|
|
|
|
|
if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) {
|
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
}
|
|
|
|
|
redisTemplate.delete(redisImageCheckCodeKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userInfoService.sendSms(deviceId, mobile);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.登录/注册", notes = "成功后返回token")
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
|
|
|
|
|
@ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
|
|
|
|
|
@PostMapping("/appLogin")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
|
|
|
|
|
public Result appLogin(HttpServletRequest request,
|
|
|
|
|
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
|
|
|
|
|
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode,
|
|
|
|
|
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
|
|
|
|
|
@RequestParam("deviceBrand") String deviceBrand) {
|
|
|
|
|
@RequestParam("deviceBrand") String deviceBrand) {
|
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
|
|
|
|
|
try {
|
|
|
|
@ -116,34 +131,30 @@ public class LoginController extends BaseController{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* token 续期
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "3.token续期", notes = "有效期7天")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
|
|
|
|
|
@PostMapping("/autoLogin")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<String> autoLogin(HttpServletRequest request,@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
|
|
|
|
|
@RequestParam("deviceBrand") String deviceBrand) {
|
|
|
|
|
return Result.success(userInfoService.autoLogin(token,deviceId,deviceBrand,getIpAddr(request)));
|
|
|
|
|
public Result<String> autoLogin(HttpServletRequest request,
|
|
|
|
|
@RequestHeader(value = "token", required = false) String token,
|
|
|
|
|
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
|
|
|
|
|
@RequestParam("deviceBrand") String deviceBrand) {
|
|
|
|
|
return Result.success(userInfoService.autoLogin(token, deviceId, deviceBrand, getIpAddr(request)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取图行验证码
|
|
|
|
|
*/
|
|
|
|
|
@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}")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
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);
|
|
|
|
|
response.setHeader("Pragma", "no-cache");
|
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
@ -155,35 +166,12 @@ public class LoginController extends BaseController{
|
|
|
|
|
vCode.write(response.getOutputStream());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "5.图形验证码+短信验证码 登录/注册后返回token")
|
|
|
|
|
@PostMapping("/appLoginWithImageCode")
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result appLoginWithImageCheckCode(
|
|
|
|
|
HttpServletRequest request,
|
|
|
|
|
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
|
|
|
|
|
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode,
|
|
|
|
|
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
|
|
|
|
|
@RequestParam("deviceBrand") String deviceBrand,
|
|
|
|
|
@VerifyParam(required = true) @RequestParam("imageCheckCode") String imageCheckCode) {
|
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
|
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
|
|
|
|
|
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
|
|
|
|
|
if (StringTools.isEmpty(redisImageCheckCode)) {
|
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
|
|
|
|
|
}
|
|
|
|
|
if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) {
|
|
|
|
|
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
|
}
|
|
|
|
|
redisTemplate.delete(redisImageCheckCodeKey);
|
|
|
|
|
return appLogin(request, mobile, mobileCheckCode, deviceId, deviceBrand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取支持的手机号国家码
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "6.获取支持的手机号国家码", notes = "v1仅支持'+86'")
|
|
|
|
|
@ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'")
|
|
|
|
|
@GetMapping("/supportedCountryCode")
|
|
|
|
|
public Result<List<CountryCodeDTO>> getSupportedCountryCode(){
|
|
|
|
|
public Result<List<CountryCodeDTO>> getSupportedCountryCode() {
|
|
|
|
|
return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|