From 60fc84976142a9019effbbb79c4d43bc4a4a3b36 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期四, 15 九月 2022 18:26:56 +0800
Subject: [PATCH] changes
---
ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java | 32 ++++++++++++--------------------
1 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java
index 4ffe3ce..61b53d8 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java
@@ -1,15 +1,14 @@
package com.sandu.ximon.admin.security.authcode;
import cn.hutool.core.lang.Snowflake;
-import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sandu.common.security.annotation.AnonymousAccess;
+import com.sandu.ximon.admin.utils.RedisUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
-import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
@@ -33,6 +32,7 @@
public class VerifyCodeController {
private final Snowflake snowflake;
+// private final RedisUtils redisUtils;
@AnonymousAccess
@@ -45,47 +45,39 @@
3.鎶婇獙璇佺爜鍥剧墖鍙戦�佺粰瀹㈡埛绔�
*/
long key = snowflake.nextId();
- ImageVerificationCode ivc = new ImageVerificationCode(); //鐢ㄦ垜浠殑楠岃瘉鐮佺被锛岀敓鎴愰獙璇佺爜绫诲璞�
+ ImageVerificationCode ivc = new ImageVerificationCode(); //鐢熸垚楠岃瘉鐮佺被瀵硅薄
BufferedImage image = ivc.getImage(); //鑾峰彇楠岃瘉鐮�
- request.getSession().setAttribute(key+"", MD5Util.md5(ivc.getText().toUpperCase())); //灏嗛獙璇佺爜鐨勬枃鏈瓨鍦╯ession涓�
-// ImageVerificationCode.output(image, response.getOutputStream());//灏嗛獙璇佺爜鍥剧墖鍝嶅簲缁欏鎴风
+ System.out.println(ivc.getText() + "----鍔犲瘑鍓嶇殑楠岃瘉鐮�");
+ RedisUtils.getBean().set(key + "", MD5Util.md5(ivc.getText().toUpperCase()), 60);
String img = getBufferedImageToBase64(image, "JPEG");
- String session_vcode = (String) request.getSession().getAttribute(key+"");
Map map = new HashMap();
-// map.put("img", "data:image/jpg;base64,"+png_base64);
map.put("img", img);
- map.put("vlue", session_vcode);
map.put("key", key);
return map;
+// return image;
}
@AnonymousAccess
@RequestMapping("/Login_authentication/{key}")
@ResponseBody
- public String Login_authentication(HttpServletRequest request, HttpServletResponse response,@PathVariable String key) throws IOException, ServletException {
+ public String Login_authentication(HttpServletRequest request, HttpServletResponse response, @PathVariable String key) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
-// String vcode = (String)map.get("session_vcode"); r6mt
-// if(vcode.isEmpty()||vcode==null){
-// return "楠岃瘉鐮佷笉鑳戒负绌�";
-// }
+
String session_vcode = (String) request.getSession().getAttribute(key); //浠巗ession涓幏鍙栫湡姝g殑楠岃瘉鐮�
- //姣旇緝杈撳叆鐨勯獙璇佺爜鍜岀湡姝g殑楠岃瘉鐮�
-// if(StrUtil.equalsIgnoreCase(session_vcode, vcode)){
-// return "true";
-// }
return session_vcode;
}
/**
- * BufferedImage杞垚 base64
+ * BufferedImage杞垚 base64
+ *
* @param bufferedImage
* @param imageFormatName
* @return
* @throws IOException
*/
- public static String getBufferedImageToBase64(BufferedImage bufferedImage,String imageFormatName) throws IOException {
- if(StringUtils.isBlank(imageFormatName)){
+ public static String getBufferedImageToBase64(BufferedImage bufferedImage, String imageFormatName) throws IOException {
+ if (StringUtils.isBlank(imageFormatName)) {
imageFormatName = "JPEG";
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
--
Gitblit v1.9.3