mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-25 20:35:35 +08:00
代码格式化
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import xyz.playedu.api.BCtx;
|
||||
import xyz.playedu.api.bus.AppBus;
|
||||
import xyz.playedu.api.bus.BackendBus;
|
||||
@@ -26,23 +33,20 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class AdminMiddleware implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private JWTService jwtService;
|
||||
@Autowired private JWTService jwtService;
|
||||
|
||||
@Autowired
|
||||
private AdminUserService adminUserService;
|
||||
@Autowired private AdminUserService adminUserService;
|
||||
|
||||
@Autowired
|
||||
private AppBus appBus;
|
||||
@Autowired private AppBus appBus;
|
||||
|
||||
@Autowired
|
||||
private BackendBus backendBus;
|
||||
@Autowired private BackendBus backendBus;
|
||||
|
||||
@Autowired
|
||||
private AppConfigService configService;
|
||||
@Autowired private AppConfigService configService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
public boolean preHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
if ("OPTIONS".equals(request.getMethod())) {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
@@ -84,7 +88,8 @@ public class AdminMiddleware implements HandlerInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean responseTransform(HttpServletResponse response, int code, String msg) throws IOException {
|
||||
private boolean responseTransform(HttpServletResponse response, int code, String msg)
|
||||
throws IOException {
|
||||
response.setStatus(code);
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
response.getWriter().print(HelperUtil.toJsonStr(JsonResponse.error(msg)));
|
||||
@@ -92,7 +97,9 @@ public class AdminMiddleware implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
public void afterCompletion(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
BCtx.remove();
|
||||
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/2/21 16:40
|
||||
*/
|
||||
@Documented
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import xyz.playedu.api.FCtx;
|
||||
import xyz.playedu.api.constant.FrontendConstant;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
@@ -21,20 +28,21 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/3/13 09:40
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FrontMiddleware implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private JWTService jwtService;
|
||||
@Autowired private JWTService jwtService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired private UserService userService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
public boolean preHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
if ("OPTIONS".equals(request.getMethod())) {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
@@ -70,7 +78,8 @@ public class FrontMiddleware implements HandlerInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean responseTransform(HttpServletResponse response, int code, String msg) throws IOException {
|
||||
private boolean responseTransform(HttpServletResponse response, int code, String msg)
|
||||
throws IOException {
|
||||
response.setStatus(code);
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
response.getWriter().print(HelperUtil.toJsonStr(JsonResponse.error(msg)));
|
||||
@@ -78,7 +87,9 @@ public class FrontMiddleware implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
public void afterCompletion(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
FCtx.remove();
|
||||
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
@@ -5,5 +9,4 @@ import java.lang.annotation.*;
|
||||
@Documented
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ImageCaptchaCheckMiddleware {
|
||||
}
|
||||
public @interface ImageCaptchaCheckMiddleware {}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -8,6 +12,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/3/12 10:44
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
@@ -8,6 +13,7 @@ import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.api.BCtx;
|
||||
import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
@@ -17,6 +23,7 @@ import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/2/21 16:42
|
||||
*/
|
||||
@Aspect
|
||||
@@ -24,17 +31,16 @@ import java.util.HashMap;
|
||||
@Slf4j
|
||||
public class BackendPermissionMiddlewareImpl {
|
||||
|
||||
@Autowired
|
||||
private BackendBus backendBus;
|
||||
@Autowired private BackendBus backendBus;
|
||||
|
||||
@Pointcut("@annotation(xyz.playedu.api.middleware.BackendPermissionMiddleware)")
|
||||
private void doPointcut() {
|
||||
}
|
||||
private void doPointcut() {}
|
||||
|
||||
@Around("doPointcut()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
BackendPermissionMiddleware middleware = signature.getMethod().getAnnotation(BackendPermissionMiddleware.class);
|
||||
BackendPermissionMiddleware middleware =
|
||||
signature.getMethod().getAnnotation(BackendPermissionMiddleware.class);
|
||||
Integer adminUserId = BCtx.getId();
|
||||
HashMap<String, Boolean> permissions = backendBus.adminUserPermissions(adminUserId);
|
||||
if (permissions.get(middleware.slug()) == null) {
|
||||
|
||||
@@ -1,30 +1,35 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.playedu.api.service.ImageCaptchaService;
|
||||
|
||||
import xyz.playedu.api.request.backend.types.ImageCaptchaRequestInterface;
|
||||
import xyz.playedu.api.service.ImageCaptchaService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ImageCaptchaCheckMiddlewareImpl {
|
||||
@Autowired
|
||||
private ImageCaptchaService imageCaptchaService;
|
||||
@Autowired private ImageCaptchaService imageCaptchaService;
|
||||
|
||||
@Pointcut("@annotation(xyz.playedu.api.middleware.ImageCaptchaCheckMiddleware)")
|
||||
private void doPointcut() {
|
||||
}
|
||||
private void doPointcut() {}
|
||||
|
||||
@Around("doPointcut()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
ImageCaptchaRequestInterface request = (ImageCaptchaRequestInterface) joinPoint.getArgs()[0];
|
||||
ImageCaptchaRequestInterface request =
|
||||
(ImageCaptchaRequestInterface) joinPoint.getArgs()[0];
|
||||
if (!imageCaptchaService.verify(request.getCaptchaKey(), request.getCaptchaValue())) {
|
||||
return JsonResponse.error("图形验证码错误");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.middleware.impl;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@@ -5,6 +9,7 @@ import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.api.exception.LimitException;
|
||||
import xyz.playedu.api.middleware.Lock;
|
||||
import xyz.playedu.api.util.RedisDistributedLock;
|
||||
|
||||
Reference in New Issue
Block a user