验证码异常优化

v1.4.1
Parker 4 years ago
parent 66d43c1638
commit 708e10d0a3

@ -25,9 +25,11 @@ import org.opsli.api.wrapper.system.tenant.TenantModel;
import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.annotation.limiter.Limiter; import org.opsli.common.annotation.limiter.Limiter;
import org.opsli.common.api.TokenThreadLocal; import org.opsli.common.api.TokenThreadLocal;
import org.opsli.common.enums.AlertType;
import org.opsli.common.exception.TokenException; import org.opsli.common.exception.TokenException;
import org.opsli.common.thread.refuse.AsyncProcessQueueReFuse; import org.opsli.common.thread.refuse.AsyncProcessQueueReFuse;
import org.opsli.common.utils.IPUtil; import org.opsli.common.utils.IPUtil;
import org.opsli.common.utils.OutputStreamUtil;
import org.opsli.core.msg.TokenMsg; import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.realm.JwtRealm; import org.opsli.core.security.shiro.realm.JwtRealm;
import org.opsli.core.utils.CaptchaUtil; import org.opsli.core.utils.CaptchaUtil;
@ -172,19 +174,23 @@ public class LoginRestController {
/** /**
* *
*/ */
@Limiter @Limiter(alertType = AlertType.ALERT)
@ApiOperation(value = "验证码", notes = "验证码") @ApiOperation(value = "验证码", notes = "验证码")
@GetMapping("captcha.jpg") @GetMapping("captcha.jpg")
public void captcha(String uuid, HttpServletResponse response) throws IOException { public void captcha(String uuid, HttpServletResponse response) throws IOException {
response.setHeader("Cache-Control", "no-store, no-cache"); response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg"); response.setContentType("image/jpeg");
//获取图片验证码 try {
BufferedImage image = CaptchaUtil.getCaptcha(uuid); //获取图片验证码
if(image != null){ BufferedImage image = CaptchaUtil.getCaptcha(uuid);
ServletOutputStream out = response.getOutputStream(); if(image != null){
ImageIO.write(image, "jpg", out); ServletOutputStream out = response.getOutputStream();
IOUtils.closeQuietly(out); ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
}catch (RuntimeException e){
OutputStreamUtil.exceptionResponse(e.getMessage(), response);
} }
} }

Loading…
Cancel
Save