Feat: captcha config

This commit is contained in:
HFO4
2019-11-13 17:22:45 +08:00
parent 7d4e212d4e
commit 9660d2f9c1
5 changed files with 69 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package controllers
import (
"cloudreve/pkg/conf"
"cloudreve/pkg/serializer"
"cloudreve/pkg/util"
"github.com/gin-gonic/gin"
@ -9,26 +10,29 @@ import (
// Captcha 获取验证码
func Captcha(c *gin.Context) {
// 验证码配置
var configD = base64Captcha.ConfigCharacter{
Height: 60,
Width: 240,
Height: conf.CaptchaConfig.Height,
Width: conf.CaptchaConfig.Width,
//const CaptchaModeNumber:数字,CaptchaModeAlphabet:字母,CaptchaModeArithmetic:算术,CaptchaModeNumberAlphabet:数字字母混合.
Mode: base64Captcha.CaptchaModeNumberAlphabet,
ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
ComplexOfNoiseDot: base64Captcha.CaptchaComplexLower,
IsShowHollowLine: false,
IsShowNoiseDot: false,
IsShowNoiseText: false,
IsShowSlimeLine: false,
IsShowSineLine: false,
CaptchaLen: 6,
Mode: conf.CaptchaConfig.Mode,
ComplexOfNoiseText: conf.CaptchaConfig.ComplexOfNoiseText,
ComplexOfNoiseDot: conf.CaptchaConfig.ComplexOfNoiseDot,
IsShowHollowLine: conf.CaptchaConfig.IsShowHollowLine,
IsShowNoiseDot: conf.CaptchaConfig.IsShowNoiseDot,
IsShowNoiseText: conf.CaptchaConfig.IsShowNoiseText,
IsShowSlimeLine: conf.CaptchaConfig.IsShowSlimeLine,
IsShowSineLine: conf.CaptchaConfig.IsShowSineLine,
CaptchaLen: conf.CaptchaConfig.CaptchaLen,
}
// 生成验证码
idKeyD, capD := base64Captcha.GenerateCaptcha("", configD)
// 将验证码UID存入Session以便后续验证
util.SetSession(c, map[string]interface{}{
"captchaID": idKeyD,
})
// 将验证码图像编码为Base64
base64stringD := base64Captcha.CaptchaWriteToBase64Encoding(capD)
c.JSON(200, serializer.Response{