package com.roy.happycaptcha;

import com.ramostear.captcha.HappyCaptcha;
import com.ramostear.captcha.support.CaptchaStyle;
import com.ramostear.captcha.support.CaptchaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：楼兰
 * @date ：Created in 2021/1/20
 * @description:
 **/

@RestController
@RequestMapping("/happycaptcha")
public class HappyCaptchaController {

    //登录 验证， 这里只需要判断验证码是否正确
    @RequestMapping("/login")
    public Object login(String verifyCode,HttpServletRequest request){
        final boolean result = HappyCaptcha.verification(request, verifyCode, true);
        if(result){
            return "success";
        }else{
            return null;
        }
    }

    //用来产生验证码
    @RequestMapping("/verifyCode")
    public void generateImage(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HappyCaptcha.require(request,response)
                .style(CaptchaStyle.ANIM)
                .type(CaptchaType.ARITHMETIC_ZH)
                .build().finish();
    }
}
