Feat: captcha

This commit is contained in:
HFO4
2019-11-13 17:03:55 +08:00
parent c7e47293db
commit 7d4e212d4e
6 changed files with 74 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
package controllers
import (
"cloudreve/pkg/serializer"
"cloudreve/pkg/util"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
)
// Captcha 获取验证码
func Captcha(c *gin.Context) {
var configD = base64Captcha.ConfigCharacter{
Height: 60,
Width: 240,
//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,
}
idKeyD, capD := base64Captcha.GenerateCaptcha("", configD)
util.SetSession(c, map[string]interface{}{
"captchaID": idKeyD,
})
base64stringD := base64Captcha.CaptchaWriteToBase64Encoding(capD)
c.JSON(200, serializer.Response{
Code: 0,
Data: base64stringD,
})
}

View File

@@ -32,6 +32,8 @@ func InitRouter() *gin.Engine {
v3.GET("Ping", controllers.Ping)
// 用户登录
v3.POST("User/Session", controllers.UserLogin)
// 验证码
v3.GET("Captcha", controllers.Captcha)
// 需要登录保护的
auth := v3.Group("")