mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-23 19:19:32 +08:00
图形验证码
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package xyz.playedu.api.middleware;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ImageCaptchaCheckMiddleware {
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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.types.ImageCaptchaRequestInterface;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ImageCaptchaCheckMiddlewareImpl {
|
||||
@Autowired
|
||||
private ImageCaptchaService imageCaptchaService;
|
||||
|
||||
@Pointcut("@annotation(xyz.playedu.api.middleware.ImageCaptchaCheckMiddleware)")
|
||||
private void doPointcut() {
|
||||
}
|
||||
|
||||
@Around("doPointcut()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
ImageCaptchaRequestInterface request = (ImageCaptchaRequestInterface) joinPoint.getArgs()[0];
|
||||
if (!imageCaptchaService.verify(request.getCaptchaKey(), request.getCaptchaValue())) {
|
||||
return JsonResponse.error("图形验证码错误");
|
||||
}
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user