登录页面通常会有验证码验证信息:

这时候用到

CaptchaUtil 图形验证码工具类:::::
package cn.hutool.captcha;/*** 图形验证码工具* * @author looly* @since 3.1.2*/
public class CaptchaUtil {/*** 创建线干扰的验证码,默认5位验证码,150条干扰线* * @param width 图片宽* @param height 图片高* @return {@link LineCaptcha}*/public static LineCaptcha createLineCaptcha(int width, int height) {return new LineCaptcha(width, height);}/*** 创建线干扰的验证码* * @param width 图片宽* @param height 图片高* @param codeCount 字符个数* @param lineCount 干扰线条数* @return {@link LineCaptcha}*/public static LineCaptcha createLineCaptcha(int width, int height, int codeCount, int lineCount) {return new LineCaptcha(width, height, codeCount, lineCount);}/*** 创建圆圈干扰的验证码,默认5位验证码,15个干扰圈* * @param width 图片宽* @param height 图片高* @return {@link CircleCaptcha}* @since 3.2.3*/public static CircleCaptcha createCircleCaptcha(int width, int height) {return new CircleCaptcha(width, height);}/*** 创建圆圈干扰的验证码* * @param width 图片宽* @param height 图片高* @param codeCount 字符个数* @param circleCount 干扰圆圈条数* @return {@link CircleCaptcha}* @since 3.2.3*/public static CircleCaptcha createCircleCaptcha(int width, int height, int codeCount, int circleCount) {return new CircleCaptcha(width, height, codeCount, circleCount);}/*** 创建扭曲干扰的验证码,默认5位验证码* * @param width 图片宽* @param height 图片高* @return {@link ShearCaptcha}* @since 3.2.3*/public static ShearCaptcha createShearCaptcha(int width, int height) {return new ShearCaptcha(width, height);}/*** 创建扭曲干扰的验证码,默认5位验证码* * @param width 图片宽* @param height 图片高* @param codeCount 字符个数* @param thickness 干扰线宽度* @return {@link ShearCaptcha}* @since 3.3.0*/public static ShearCaptcha createShearCaptcha(int width, int height, int codeCount, int thickness) {return new ShearCaptcha(width, height, codeCount, thickness);}
}
package cn.yunmark.login.controller;import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.date.DateUtil;
import cn.yunmark.aop.logging.annotation.ApiLog;
import cn.yunmark.common.redis.RedisUtils;
import cn.yunmark.common.utils.ResponseUtil;
import cn.yunmark.core.errors.ErrorConstants;
import cn.yunmark.examdetail.service.ExamDetailService;
import cn.yunmark.examdetail.service.dto.ExamDetailDTO;
import cn.yunmark.grade.service.StudentGradeService;
import cn.yunmark.grade.service.dto.StudentGradeDTO;
import cn.yunmark.grade.service.dto.StudentInfoExcelDTO;
import cn.yunmark.login.model.LoginDTO;
import cn.yunmark.login.model.LoginVo;
import cn.yunmark.security.jwt.TokenProvider;
import cn.yunmark.security.util.SecurityUtils;
import cn.yunmark.sys.constant.enums.LogTypeEnum;
import cn.yunmark.sys.model.LoginForm;
import cn.yunmark.sys.service.dto.UserDTO;
import cn.yunmark.sys.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.web.bind.annotation.*;import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;/*** 学生登录Controller* @author yunmark* @version @2022/3/25 22:01*/
@Api(tags ="学生成绩信息")
@Slf4j
@RestController
@RequestMapping(value = "/zsb/student")
public class StudentLoginController {@Autowiredprivate StudentGradeService studentGradeService;@Autowiredprivate ExamDetailService examDetailService;/*** 用户登录* @param loginForm* @param session* @return*/@PostMapping("check")@ApiLog(value = "用户校验", type = LogTypeEnum.LOGIN)@ApiOperation("登录接口")public Map<String,Object> login(@RequestBody LoginDTO loginForm,String codeSign) {Map<String, Object> res = new HashMap<>();String sfzh = loginForm.getSfzh();String code = loginForm.getCode();String ksh = loginForm.getKsh();RedisUtils utils = RedisUtils.getInstance();String rediscode = (String) utils.get(codeSign);if (!code.equals(rediscode) && null != code) {res.put("code", 500);res.put("msg", "考生信息有误,请确认后重新输入");return res;}String nf = DateUtil.format(new Date(), "yyyy");StudentGradeDTO studentGradeDTO = studentGradeService.selectOneStd(ksh, sfzh, nf);if (studentGradeDTO == null) {res.put("code", 500);res.put("msg", "身份信息有误");return res;}//获取有效考试须知ExamDetailDTO examDetailDTO = examDetailService.getByStatus(nf);if (examDetailDTO == null) {examDetailDTO = examDetailService.getDefault();}LoginVo loginVo = new LoginVo();loginVo.setExamDetailDTO(examDetailDTO);loginVo.setStudentGradeDTO(studentGradeDTO);res.put("code", 200);res.put("msg", "校验成功");res.put("data", loginVo);return res;}/*** 获取登陆验证码* @param response* @param session* @throws*/@ApiOperation ("获取验证码")@ApiLog("获取验证码")@GetMapping("getCode")public void getCode(HttpServletResponse response, HttpSession session){//HuTool定义图形验证码的长和宽,验证码的位数,干扰线的条数LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36,4,50);//将验证码放入sessionsession.setAttribute("code",lineCaptcha.getCode());try {ServletOutputStream outputStream = response.getOutputStream();lineCaptcha.write(outputStream);outputStream.close();} catch (IOException e) {log.error ("{}", e );}}}

LoginController________相关推荐

最新文章

  1. 医学论文摘要撰写的四要素以及注意事项
  2. excel xml mysql_数据库表转换为xml格式,excel转换为xml格式文件
  3. Content-Disposition 响应头,设置文件在浏览器打开还是下载
  4. 电脑中毒的表现有哪些?电脑中毒了怎么办?
  5. java状态模式和策略模式_Java状态和策略设计模式之间的差异
  6. leetcode50. Pow(x, n)(快速幂)
  7. 中国首台千万亿次超级计算机,中国首台千万亿次超级计算机首批设备开始试用...
  8. mysql 加随机数,如何插入随机数MySql
  9. Windows RDP协议重大漏洞后发现黑客开始大规模扫瞄
  10. 字节跳动面试真题:java程序设计基础教程
  11. osmdroid 6.0.1加载天地图在线矢量和影像数据
  12. 缘起和性空-佛教对自然的看法(转载整理)
  13. 陈强《计量经济学及Stata应用》习题答案
  14. iview 组件 设置头像更换
  15. c语言实验设备管理系统设计作业,C语言课程设计实验设备管理系统设计
  16. 【最全】Google Chrome20-83各版本下载链接整理
  17. 找到任何你想要找的人-王春明大佬超强干货
  18. 聊聊Python ctypes 模块
  19. 数据结构与算法 (1)复杂度---(时间复杂度)
  20. 软件工程:传统软件工程 vs 敏捷软件开发

热门文章

  1. 乔布斯的10个与众不同:践行另类思考
  2. maskrcnn-benchmark 代码详解之 resnet.py
  3. Web 渗透题(三)
  4. Python3+Selenium爬虫实战:微博粉丝榜水分大揭秘
  5. java中相等和同一的区别
  6. [翻译]如何使用Visual Studio的Debugger调试NDS自制软件
  7. 如何在HTML中播放flash
  8. 千牛包表包下载_带有服务器端处理和VueJS组件的数据表包
  9. 编写一个子函数求主调函数中两个变量的和与积
  10. 【文献翻译】客座社论:工业自动化和控制系统的配置安全