Search in sources :

Example 1 with RandomVerifyCode

use of com.topcom.cms.utils.RandomVerifyCode in project topcom-cloud by 545314690.

the class ServiceController method verifyCode.

@RequestMapping(method = RequestMethod.GET, value = "verifyCode")
@ResponseBody
public String verifyCode(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // 设置响应头信息,告诉浏览器不要缓存此内容
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expire", 0);
    /**
     * 加上这个前台ajax才能获得自定义的header
     * response.setHeader("Access-Control-Expose-Headers", "custom header");
     * response.setHeader("costum header", "custom header value");
     */
    response.setHeader("Access-Control-Expose-Headers", codeHeader);
    String code = UUID.randomUUID().toString();
    response.setHeader(codeHeader, code);
    RandomVerifyCode randomVerifyCode = new RandomVerifyCode();
    try {
        // 输出图片方法
        RandomVerifyCode.VerifyCode verifyCode = randomVerifyCode.getBase64Randcode();
        if (verifyCode != null) {
            SubjectUtil.setCaptcha(code, verifyCode.code);
            return verifyCode.image;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : RandomVerifyCode(com.topcom.cms.utils.RandomVerifyCode) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RandomVerifyCode

use of com.topcom.cms.utils.RandomVerifyCode in project topcom-cloud by 545314690.

the class ServiceController method verifyCode2.

@RequestMapping(method = RequestMethod.GET, value = "verifyCode2")
public void verifyCode2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // 设置相应类型,告诉浏览器输出的内容为图片
    response.setContentType("image/jpeg");
    // 设置响应头信息,告诉浏览器不要缓存此内容
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expire", 0);
    /**
     * 加上这个前台ajax才能获得自定义的header
     * response.setHeader("Access-Control-Expose-Headers", "custom header");
     * response.setHeader("costum header", "custom header value");
     */
    response.setHeader("Access-Control-Expose-Headers", codeHeader);
    String code = UUID.randomUUID().toString();
    response.setHeader(codeHeader, code);
    RandomVerifyCode randomVerifyCode = new RandomVerifyCode();
    try {
        // 输出图片方法
        String verifyCode = randomVerifyCode.writeRandcode(request, response);
        SubjectUtil.setCaptcha(code, verifyCode);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RandomVerifyCode(com.topcom.cms.utils.RandomVerifyCode) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RandomVerifyCode (com.topcom.cms.utils.RandomVerifyCode)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1