mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 04:22:43 +08:00
增加testing配置
This commit is contained in:
parent
d1d7c43a3a
commit
1edc205e9f
@ -27,6 +27,9 @@ public class PlayEduConfig {
|
||||
@Value("${spring.profiles.active}")
|
||||
private String env;
|
||||
|
||||
@Value("${playedu.core.testing}")
|
||||
private Boolean testing;
|
||||
|
||||
@Value("${playedu.limiter.duration}")
|
||||
private Long limiterDuration;
|
||||
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import xyz.playedu.api.BCtx;
|
||||
import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.config.PlayEduConfig;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.event.AdminUserLoginEvent;
|
||||
@ -53,6 +54,8 @@ public class LoginController {
|
||||
|
||||
@Autowired private RateLimiterService rateLimiterService;
|
||||
|
||||
@Autowired private PlayEduConfig playEduConfig;
|
||||
|
||||
@PostMapping("/login")
|
||||
public JsonResponse login(@RequestBody @Validated LoginRequest loginRequest) {
|
||||
AdminUser adminUser = adminUserService.findByEmail(loginRequest.email);
|
||||
@ -62,7 +65,7 @@ public class LoginController {
|
||||
|
||||
String limitKey = "admin-login-limit:" + loginRequest.getEmail();
|
||||
Long reqCount = rateLimiterService.current(limitKey, 3600L);
|
||||
if (reqCount > 5) {
|
||||
if (reqCount > 5 && !playEduConfig.getTesting()) {
|
||||
Long exp = RedisUtil.ttlWithoutPrefix(limitKey);
|
||||
return JsonResponse.error(
|
||||
String.format("您的账号已被锁定,请%s后重试", exp > 60 ? exp / 60 + "分钟" : exp + "秒"));
|
||||
|
@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import xyz.playedu.api.FCtx;
|
||||
import xyz.playedu.api.config.PlayEduConfig;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.event.UserLoginEvent;
|
||||
import xyz.playedu.api.event.UserLogoutEvent;
|
||||
@ -52,6 +53,8 @@ public class LoginController {
|
||||
|
||||
@Autowired private RateLimiterService rateLimiterService;
|
||||
|
||||
@Autowired private PlayEduConfig playEduConfig;
|
||||
|
||||
@PostMapping("/password")
|
||||
public JsonResponse password(@RequestBody @Validated LoginPasswordRequest req)
|
||||
throws LimitException {
|
||||
@ -64,7 +67,7 @@ public class LoginController {
|
||||
|
||||
String limitKey = "login-limit:" + req.getEmail();
|
||||
Long reqCount = rateLimiterService.current(limitKey, 600L);
|
||||
if (reqCount >= 10) {
|
||||
if (reqCount >= 10 && !playEduConfig.getTesting()) {
|
||||
Long exp = RedisUtil.ttlWithoutPrefix(limitKey);
|
||||
return JsonResponse.error(
|
||||
String.format("您的账号已被锁定,请%s后重试", exp > 60 ? exp / 60 + "分钟" : exp + "秒"));
|
||||
|
@ -65,6 +65,8 @@ sa-token:
|
||||
token-prefix: "Bearer"
|
||||
|
||||
playedu:
|
||||
core:
|
||||
testing: false
|
||||
limiter:
|
||||
duration: 60
|
||||
limit: 240
|
||||
|
Loading…
x
Reference in New Issue
Block a user