package com.das.modules.auth.controller;

import cn.hutool.core.util.IdUtil;
import com.das.common.captcha.CaptchaProperties;
import com.das.common.captcha.CaptchaUtil;
import com.das.common.captcha.CaptchaVO;
import com.das.common.result.R;
import com.das.common.utils.AdminRedisTemplate;
import com.das.modules.auth.domain.LoginUserDetails;
import com.das.modules.auth.domain.vo.LoginVO;
import com.das.modules.auth.service.ILoginService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.code.kaptcha.Producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;

/**
 * @author chenhaojie
 * @Description 获取验证码
 */
@Slf4j
@RequestMapping("/api")
@RestController
public class CaptchaImageController {
    @Resource
    private Producer producer;
    @Resource
    private CaptchaProperties captchaProperties;

     @Value("${aesKey}")
     String key;
    @Resource
    private AdminRedisTemplate adminRedisTemplate;

    /**
     * 获取验证码
     */
    @PostMapping("/captchaImage")
    public R<CaptchaVO> getCaptcha() {
        String uuid = IdUtil.fastSimpleUUID();
        String imageBase64Str = CaptchaUtil.getImageBase64Str(producer, adminRedisTemplate, captchaProperties, uuid);
        CaptchaVO captchaVO = new CaptchaVO(uuid, imageBase64Str);
        return R.success(captchaVO);
    }


}
