|
|
@ -44,7 +44,6 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
* 控制器层
|
|
|
|
* 控制器层
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Administrator
|
|
|
|
* @author Administrator
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@CrossOrigin
|
|
|
@ -84,7 +83,7 @@ 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")){
|
|
|
|
if (sendSmsReq.getMobile().equals("18812345678")) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 测试用手机号
|
|
|
|
* 测试用手机号
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -112,7 +111,7 @@ 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())) {
|
|
|
|
if ("18812345678".equals(loginReq.getMobile())) {
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
@ -139,9 +138,10 @@ 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")
|
|
|
|
public Result<String> appleIdLogin(HttpServletRequest request,@VerifyParam AppleLoginReq appleLoginReq) {
|
|
|
|
public Result<String> appleIdLogin(HttpServletRequest request, @VerifyParam AppleLoginReq appleLoginReq) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 无手机号和验证码
|
|
|
|
// 无手机号和验证码
|
|
|
@ -163,7 +163,7 @@ public class LoginController extends BaseController {
|
|
|
|
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());
|
|
|
@ -173,15 +173,14 @@ public class LoginController extends BaseController {
|
|
|
|
return Result.success(token);
|
|
|
|
return Result.success(token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
|
|
|
|
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
|
|
|
|
@PostMapping("/wxIdLogin")
|
|
|
|
@PostMapping("/wxIdLogin")
|
|
|
|
public Result<String> wxIdLogin(HttpServletRequest request,@VerifyParam WeChatLoginReq weChatLoginReq) {
|
|
|
|
public Result<String> wxIdLogin(HttpServletRequest request, @VerifyParam WeChatLoginReq weChatLoginReq) {
|
|
|
|
|
|
|
|
|
|
|
|
// 如果有手机号,是首次微信登录时绑定流程
|
|
|
|
// 如果有手机号,是首次微信登录时绑定流程
|
|
|
|
if(StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
|
|
|
|
if (StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
|
|
|
|
//得到缓存中的验证码
|
|
|
|
//得到缓存中的验证码
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
|
|
|
|
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
|
|
|
|
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
|
|
|
@ -191,11 +190,11 @@ public class LoginController extends BaseController {
|
|
|
|
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
|
|
|
|
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return weChatAouth2Service.register(weChatLoginReq,getIpAddr(request));
|
|
|
|
return weChatAouth2Service.register(weChatLoginReq, getIpAddr(request));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录,如果有记录登录正常执行,如果无记录,返回状态到上面绑定手机号流程
|
|
|
|
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录,如果有记录登录正常执行,如果无记录,返回状态到上面绑定手机号流程
|
|
|
|
return weChatAouth2Service.login(weChatLoginReq,getIpAddr(request));
|
|
|
|
return weChatAouth2Service.login(weChatLoginReq, getIpAddr(request));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -286,7 +285,6 @@ public class LoginController extends BaseController {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* authorization 续期
|
|
|
|
* authorization 续期
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -303,7 +301,7 @@ public class LoginController extends BaseController {
|
|
|
|
* 获取图行验证码
|
|
|
|
* 获取图行验证码
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@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,
|
|
|
@ -318,12 +316,14 @@ public class LoginController extends BaseController {
|
|
|
|
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,
|
|
|
@ -349,15 +349,17 @@ public class LoginController extends BaseController {
|
|
|
|
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(@RequestHeader(value = "Authorization", required = true) String authorization){
|
|
|
|
public Result<Void> logout(@RequestHeader(value = "Authorization", required = true) String authorization) {
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -372,17 +374,17 @@ public class LoginController extends BaseController {
|
|
|
|
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) {
|
|
|
|
if (userInfo != null) {
|
|
|
|
//生成token
|
|
|
|
//生成token
|
|
|
|
String token = jwtUtil.createJWT(userInfo.getId(),userInfo.getUserName(),"artist","");
|
|
|
|
String token = jwtUtil.createJWT(userInfo.getId(), userInfo.getUserName(), "artist", "");
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
map.put("token",token);
|
|
|
|
map.put("token", token);
|
|
|
|
map.put("roles","artist");
|
|
|
|
map.put("roles", "artist");
|
|
|
|
map.put("name",userInfo.getUserName());
|
|
|
|
map.put("name", userInfo.getUserName());
|
|
|
|
return Result.success(map);
|
|
|
|
return Result.success(map);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
|
|
|
|
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
|
|
|
@ -404,7 +406,7 @@ public class LoginController extends BaseController {
|
|
|
|
return Result.success(uuid);
|
|
|
|
return Result.success(uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0是未完成,其余是已完成状态的token")
|
|
|
|
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0-未完成 1-已扫码 other-token")
|
|
|
|
@GetMapping(value = "/check/qr")
|
|
|
|
@GetMapping(value = "/check/qr")
|
|
|
|
public Result<String> getCountryCode(String uuid) {
|
|
|
|
public Result<String> getCountryCode(String uuid) {
|
|
|
|
return Result.success(redisTemplate.opsForValue().get(uuid).toString());
|
|
|
|
return Result.success(redisTemplate.opsForValue().get(uuid).toString());
|
|
|
@ -412,7 +414,7 @@ public class LoginController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
|
|
|
|
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
|
|
|
|
@GetMapping(value = "/getLoginQr")
|
|
|
|
@GetMapping(value = "/getLoginQr")
|
|
|
|
public void createCodeImg(HttpServletRequest request, HttpServletResponse response, String uuid){
|
|
|
|
public void createCodeImg(HttpServletRequest request, HttpServletResponse response, String uuid) {
|
|
|
|
response.setHeader("Pragma", "No-cache");
|
|
|
|
response.setHeader("Pragma", "No-cache");
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
|
|
|
|
|
|
|
@ -425,14 +427,14 @@ public class LoginController extends BaseController {
|
|
|
|
if (o == null) {
|
|
|
|
if (o == null) {
|
|
|
|
throw new BizException("二维码失效!");
|
|
|
|
throw new BizException("二维码失效!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!String.valueOf(o).equals("0")) {
|
|
|
|
if (!String.valueOf(o).equals("0")) {
|
|
|
|
throw new BizException("登录认证已完成");
|
|
|
|
throw new BizException("登录认证已完成");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
response.setHeader("uuid", uuid);
|
|
|
|
response.setHeader("uuid", uuid);
|
|
|
|
// 这里是开源工具类 hutool里的QrCodeUtil
|
|
|
|
// 这里是开源工具类 hutool里的QrCodeUtil
|
|
|
|
// 网址:http://hutool.mydoc.io/
|
|
|
|
// 网址:http://hutool.mydoc.io/
|
|
|
|
QrCodeUtil.generate(uuid, 300, 300, "jpg",response.getOutputStream());
|
|
|
|
QrCodeUtil.generate(uuid, 300, 300, "jpg", response.getOutputStream());
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -440,11 +442,13 @@ public class LoginController extends BaseController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等")
|
|
|
|
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等")
|
|
|
|
@PostMapping(value = "/bindUserIdAndToken")
|
|
|
|
@PostMapping(value = "/scanOrConfirm")
|
|
|
|
public Result<String> bindUserIdAndToken(@RequestParam("token") String token ,
|
|
|
|
public Result<Void> scanOrConfirm(@RequestParam("token") String token,
|
|
|
|
@RequestParam("userId") String userId){
|
|
|
|
@RequestParam("userId") String userId,
|
|
|
|
|
|
|
|
@RequestParam("type") Integer type) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return Result.success(userInfoService.bindUserIdAndToken(userId,token));
|
|
|
|
userInfoService.scan(userId, token, type);
|
|
|
|
|
|
|
|
return Result.success();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|