Commit 88968a19 authored by mx's avatar mx

验证码

parent 6a0d2343
......@@ -4,30 +4,34 @@ package org.rcisoft.sys.sysuser.controller;
/*固定导入*/
import cn.hutool.core.codec.Base64Encoder;
import com.google.code.kaptcha.Producer;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.core.anno.CyEptSm4EnableAnno;
import org.rcisoft.core.anno.CyOpeLogAnno;
import org.rcisoft.core.constant.CySysCons;
import org.rcisoft.core.exception.CyServiceException;
import org.rcisoft.core.operlog.enums.CyLogTypeEnum;
import org.rcisoft.core.result.enums.CyReSysExcEnum;
import org.rcisoft.core.util.CyEpExcelUtil;
import org.rcisoft.core.util.CyQrCodeUtil;
import org.rcisoft.core.service.CyRedisService;
import org.rcisoft.core.util.*;
import org.rcisoft.integration.jieLink.service.IJieLinkService;
import org.rcisoft.sys.sysuser.dto.ExportUserDTO;
import org.rcisoft.sys.sysuser.entity.SysUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.rcisoft.core.result.CyResult;
import org.rcisoft.core.util.CyResultGenUtil;
import org.rcisoft.core.model.CyPersistModel;
import org.rcisoft.core.constant.CyMessCons;
import org.rcisoft.core.controller.CyPaginationController;
import org.rcisoft.core.model.CyGridModel;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
......@@ -36,7 +40,10 @@ import org.springframework.web.multipart.MultipartFile;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by cy on 2022年11月16日 下午3:19:19.
......@@ -45,6 +52,20 @@ import java.util.List;
@RequestMapping("/sysUserManage")
public class SysUserController extends CyPaginationController<SysUser> {
@Resource(
name = "captchaProducer"
)
private Producer captchaProducer;
@Resource(
name = "captchaProducerMath"
)
private Producer captchaProducerMath;
@Autowired(
required = false
)
private CyRedisService cyRedisServiceImpl;
@Value("${cy.captchaType}")
private String captchaType;
@Autowired
private SysUserService sysUserServiceImpl;
......@@ -52,6 +73,7 @@ public class SysUserController extends CyPaginationController<SysUser> {
@Autowired
private IJieLinkService jieLinkServiceImpl;
//@PreAuthorize("@cyPerm.hasPerm('sys:user:add')")
@CyOpeLogAnno(title = "system-用户表管理-新增用户表", businessType = CyLogTypeEnum.INSERT)
@ApiOperation(value = "添加用户表", notes = "添加用户表")
......@@ -230,11 +252,11 @@ public class SysUserController extends CyPaginationController<SysUser> {
@ApiOperation(value = "导入用户信息", notes = "导入用户信息")
@PostMapping("/importExcel")
@CyEptSm4EnableAnno
public CyResult importSysUser(MultipartFile file,HttpServletResponse response) {
public CyResult importSysUser(MultipartFile file, HttpServletResponse response) {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
sysUserServiceImpl.importUserExcel(file,response));
sysUserServiceImpl.importUserExcel(file, response));
}
/**
......@@ -274,4 +296,33 @@ public class SysUserController extends CyPaginationController<SysUser> {
png_base64);
}
@GetMapping({"/captchaImage"})
public CyResult getCode(HttpServletResponse response) throws IOException {
CyResult cyResult = new CyResult();
String uuid = CyIdGenUtil.uuid();
String verifyKey = "captcha_codes:" + uuid;
String capStr = null;
String code = null;
BufferedImage image = null;
if ("math".equals(this.captchaType)) {
String capText = this.captchaProducerMath.createText();
capStr = capText.substring(0, capText.lastIndexOf("@"));
code = capText.substring(capText.lastIndexOf("@") + 1);
image = this.captchaProducerMath.createImage(capStr);
} else if ("char".equals(this.captchaType)) {
capStr = code = this.captchaProducer.createText();
image = this.captchaProducer.createImage(capStr);
}
this.cyRedisServiceImpl.set(verifyKey, code, CySysCons.CAPTCHA_EXPIRATION);
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
ImageIO.write(image, "jpg", os);
Map map = new HashMap();
map.put("captchaOnOff", true);
map.put("uuid", uuid);
map.put("img", CyBase64Util.encode(os.toByteArray()));
cyResult.setSucessMessage("操作成功", map);
return cyResult;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment