Search in sources :

Example 1 with CircleCaptcha

use of cn.hutool.captcha.CircleCaptcha in project Jpom by dromara.

the class LoginControl method randCode.

/**
 * 验证码
 *
 * @throws IOException IO
 */
@RequestMapping(value = "randCode.png", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@NotLogin
public void randCode() throws IOException {
    int height = 50;
    CircleCaptcha circleCaptcha = new CircleCaptcha(100, height, 4, 8);
    // 设置为默认字体
    circleCaptcha.setFont(new Font(null, Font.PLAIN, (int) (height * 0.75)));
    circleCaptcha.createCode();
    HttpServletResponse response = getResponse();
    circleCaptcha.write(response.getOutputStream());
    String code = circleCaptcha.getCode();
    setSessionAttribute(LOGIN_CODE, code);
}
Also used : CircleCaptcha(cn.hutool.captcha.CircleCaptcha) HttpServletResponse(javax.servlet.http.HttpServletResponse) NotLogin(io.jpom.common.interceptor.NotLogin)

Example 2 with CircleCaptcha

use of cn.hutool.captcha.CircleCaptcha in project RuoYi-Flowable-Plus by KonBAI-Q.

the class CaptchaConfig method circleCaptcha.

/**
 * 圆圈干扰验证码
 */
@Lazy
@Bean
public CircleCaptcha circleCaptcha() {
    CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(width, height);
    captcha.setBackground(background);
    captcha.setFont(font);
    return captcha;
}
Also used : CircleCaptcha(cn.hutool.captcha.CircleCaptcha) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean)

Example 3 with CircleCaptcha

use of cn.hutool.captcha.CircleCaptcha in project ruoyi-vue-pro by YunaiV.

the class CaptchaServiceImpl method getCaptchaImage.

@Override
public CaptchaImageRespVO getCaptchaImage() {
    if (!Boolean.TRUE.equals(enable)) {
        return CaptchaImageRespVO.builder().enable(enable).build();
    }
    // 生成验证码
    CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(captchaProperties.getWidth(), captchaProperties.getHeight());
    // 缓存到 Redis 中
    String uuid = IdUtil.fastSimpleUUID();
    captchaRedisDAO.set(uuid, captcha.getCode(), captchaProperties.getTimeout());
    // 返回
    return CaptchaConvert.INSTANCE.convert(uuid, captcha).setEnable(enable);
}
Also used : CircleCaptcha(cn.hutool.captcha.CircleCaptcha)

Example 4 with CircleCaptcha

use of cn.hutool.captcha.CircleCaptcha in project RuoYi-Vue-Plus by JavaLionLi.

the class CaptchaConfig method circleCaptcha.

/**
 * 圆圈干扰验证码
 */
@Lazy
@Bean
public CircleCaptcha circleCaptcha() {
    CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(width, height);
    captcha.setBackground(background);
    captcha.setFont(font);
    return captcha;
}
Also used : CircleCaptcha(cn.hutool.captcha.CircleCaptcha) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean)

Aggregations

CircleCaptcha (cn.hutool.captcha.CircleCaptcha)4 Bean (org.springframework.context.annotation.Bean)2 Lazy (org.springframework.context.annotation.Lazy)2 NotLogin (io.jpom.common.interceptor.NotLogin)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1