1.修改登录返回为token,2.增加短信调用频次限制

main
Gary 1 year ago
parent 247bcce796
commit 4e70d7819f

@ -9,4 +9,12 @@ public class StringTools {
} }
return false; return false;
} }
public static String getFileSuffix(String fileName) {
Integer index = fileName.lastIndexOf(".");
if (index == -1) {
return "";
}
String suffix = fileName.substring(index);
return suffix;
}
} }

@ -11,4 +11,7 @@ public class Constants {
public static final String TOKEN_ROLE_APP_USER="user"; public static final String TOKEN_ROLE_APP_USER="user";
public static final String TOKEN_ROLE_ADMIN_USER="admin"; public static final String TOKEN_ROLE_ADMIN_USER="admin";
public static final String TOKEN_ROLE_TOURIST="tourist"; public static final String TOKEN_ROLE_TOURIST="tourist";
public static final String FOLDER_AVATAR = "avatar/";
} }

@ -90,7 +90,7 @@ public class UserController {
return Result.success(map); return Result.success(map);
} }
@ApiOperation(value = "2.登录/注册",notes="成功后返回用户信息和token") @ApiOperation(value = "2.登录/注册",notes="成功后返回token")
@PostMapping("/appLogin/{mobile}/{mobileCheckCode}") @PostMapping("/appLogin/{mobile}/{mobileCheckCode}")
@GlobalInterceptor @GlobalInterceptor
public Result appLogin( @PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile, public Result appLogin( @PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile,
@ -107,11 +107,8 @@ public class UserController {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
} }
User user = userService.loginOrRegister(mobile); User user = userService.loginOrRegister(mobile);
UserRespDTO userRespDTO=new UserRespDTO();
BeanUtils.copyProperties(user, userRespDTO);
String token = jwtUtil.createJWT(user.getId(),user.getNickname(),Constants.TOKEN_ROLE_APP_USER); String token = jwtUtil.createJWT(user.getId(),user.getNickname(),Constants.TOKEN_ROLE_APP_USER);
userRespDTO.setToken(token); return Result.success(token);
return Result.success(userRespDTO);
}finally { }finally {
redisTemplate.delete(redisMobileCheckCodeKey); redisTemplate.delete(redisMobileCheckCodeKey);
} }
@ -120,22 +117,18 @@ public class UserController {
@ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist") @ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist")
@GetMapping("/touristLogin") @GetMapping("/touristLogin")
public Result<UserRespDTO> touristLogin() { public Result<String> touristLogin() {
UserRespDTO userRespDTO=new UserRespDTO();
userRespDTO.setId(String.valueOf(idWorker.nextId()));
String nickName="游客-"+NickNameUtil.getRandomNickName(); String nickName="游客-"+NickNameUtil.getRandomNickName();
userRespDTO.setNickname("游客-"+NickNameUtil.getRandomNickName()); String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST);
String token = jwtUtil.createJWT(userRespDTO.getId(),nickName,Constants.TOKEN_ROLE_TOURIST); return Result.success(token);
userRespDTO.setToken(token);
return Result.success(userRespDTO);
} }
/** /**
* *
*/ */
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天最多发50次请求") @ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一分钟内只能请求1次")
@PostMapping("/sendsms/{mobile}") @PostMapping("/sendsms/{mobile}")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50) @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.MINUTE, requestFrequencyThreshold = 1)
public Result<Void> sendSms(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile) { public Result<Void> sendSms(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile) {
userService.sendSms(mobile); userService.sendSms(mobile);
return Result.success(); return Result.success();

Loading…
Cancel
Save