-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2af3d35
commit b356abc
Showing
8 changed files
with
40 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.3.7.RELEASE</version> | ||
<version>2.7.5</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
|
@@ -44,30 +44,29 @@ | |
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>2.1.3</version> | ||
<version>2.2.2</version> | ||
</dependency> | ||
<!-- 验证码 --> | ||
<dependency> | ||
<groupId>com.github.penggle</groupId> | ||
<artifactId>kaptcha</artifactId> | ||
<version>2.3.2</version> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-captcha</artifactId> | ||
<version>5.8.7</version> | ||
</dependency> | ||
<!-- commonmark core --> | ||
<dependency> | ||
<groupId>com.atlassian.commonmark</groupId> | ||
<artifactId>commonmark</artifactId> | ||
<version>0.8.0</version> | ||
<version>0.17.0</version> | ||
</dependency> | ||
<!-- commonmark table --> | ||
<dependency> | ||
<groupId>com.atlassian.commonmark</groupId> | ||
<artifactId>commonmark-ext-gfm-tables</artifactId> | ||
<version>0.8.0</version> | ||
<version>0.17.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.28</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
|
@@ -90,4 +89,4 @@ | |
@email [email protected] | ||
@link http://13blog.site | ||
--> | ||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 13 additions & 34 deletions
47
src/main/java/com/site/blog/my/core/controller/common/CommonController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,30 @@ | ||
package com.site.blog.my.core.controller.common; | ||
|
||
import com.google.code.kaptcha.impl.DefaultKaptcha; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import cn.hutool.captcha.CaptchaUtil; | ||
import cn.hutool.captcha.ShearCaptcha; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
import javax.imageio.ImageIO; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.awt.image.BufferedImage; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
/** | ||
* @author 13 | ||
* @qq交流群 796794009 | ||
* @email [email protected] | ||
* @link http://13blog.site | ||
*/ | ||
|
||
@Controller | ||
public class CommonController { | ||
|
||
@Autowired | ||
private DefaultKaptcha captchaProducer; | ||
|
||
@GetMapping("/common/kaptcha") | ||
public void defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { | ||
byte[] captchaOutputStream = null; | ||
ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream(); | ||
try { | ||
//生产验证码字符串并保存到session中 | ||
String verifyCode = captchaProducer.createText(); | ||
httpServletRequest.getSession().setAttribute("verifyCode", verifyCode); | ||
BufferedImage challenge = captchaProducer.createImage(verifyCode); | ||
ImageIO.write(challenge, "jpg", imgOutputStream); | ||
} catch (IllegalArgumentException e) { | ||
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); | ||
return; | ||
} | ||
captchaOutputStream = imgOutputStream.toByteArray(); | ||
httpServletResponse.setHeader("Cache-Control", "no-store"); | ||
httpServletResponse.setHeader("Pragma", "no-cache"); | ||
httpServletResponse.setDateHeader("Expires", 0); | ||
httpServletResponse.setContentType("image/jpeg"); | ||
ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream(); | ||
responseOutputStream.write(captchaOutputStream); | ||
responseOutputStream.flush(); | ||
responseOutputStream.close(); | ||
httpServletResponse.setContentType("image/png"); | ||
|
||
ShearCaptcha shearCaptcha= CaptchaUtil.createShearCaptcha(150, 30, 4, 2); | ||
|
||
// 验证码存入session | ||
httpServletRequest.getSession().setAttribute("verifyCode", shearCaptcha); | ||
|
||
// 输出图片流 | ||
shearCaptcha.write(httpServletResponse.getOutputStream()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/main/java/com/site/blog/my/core/controller/common/KaptchaConfig.java
This file was deleted.
Oops, something went wrong.
5 changes: 1 addition & 4 deletions
5
src/test/java/com/site/blog/my/core/MyBlogApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters