commit
continuous-integration/drone/push Build is passing Details

master
黄海 4 years ago
parent c985e45c71
commit 52fd93ef04

@ -5,8 +5,10 @@
</component>
<component name="ChangeListManager">
<list default="true" id="19c8c37d-a056-451c-a29d-fb612b9a3e2f" name="Default Changelist" comment="commit">
<change afterPath="$PROJECT_DIR$/Business/CaptchaRelate/CaptchaController/RedisStore.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Business/CaptchaRelate/CaptchaController/CaptchaController.go" beforeDir="false" afterPath="$PROJECT_DIR$/Business/CaptchaRelate/CaptchaController/CaptchaController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/static/getcapt.html" beforeDir="false" afterPath="$PROJECT_DIR$/static/getcapt.html" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -16,8 +18,8 @@
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
<option value="HTML File" />
<option value="Go File" />
</list>
</option>
</component>
@ -66,6 +68,14 @@
</key>
</component>
<component name="RunManager" selected="Go Build.go build dsSzxy">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="dsSzxy" />
<working_directory value="$PROJECT_DIR$" />
<kind value="FILE" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="go build dsSzxy" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
<module name="dsSzxy" />
<working_directory value="$PROJECT_DIR$" />
@ -84,6 +94,15 @@
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="dsSzxy" />
<working_directory value="$PROJECT_DIR$" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Build.go build dsSzxy" />

@ -13,13 +13,16 @@ import (
// Routers 模块的路由配置
func Routers(r *gin.RouterGroup) {
rr := r.Group("/captchaRelate")
rr.GET("/GetOne", GetOne)
rr.POST("/Verify", Verify)
rr.GET("/getCaptcha", getCaptcha)
rr.POST("/verifyCaptcha", verifyCaptcha)
}
// 设置自带的store
var store = base64Captcha.DefaultMemStore
//使用redis作为store
//var store = RedisStore{}
// CaptchaResult 存储验证码的结构
type CaptchaResult struct {
Id string `json:"id"`
@ -27,7 +30,7 @@ type CaptchaResult struct {
}
// GetOne 生成图形化验证码
func GetOne(c *gin.Context) {
func getCaptcha(c *gin.Context) {
id, b64s, err := CaptMake()
if err != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "info": "发生错误!"})
@ -41,7 +44,7 @@ func GetOne(c *gin.Context) {
}
// Verify 验证captcha是否正确
func Verify(c *gin.Context) {
func verifyCaptcha(c *gin.Context) {
id := c.PostForm("id")
capt := c.PostForm("capt")
if id == "" || capt == "" {
@ -76,7 +79,6 @@ func CaptMake() (id, b64s string, err error) {
},
Fonts: []string{"wqy-microhei.ttc"},
}
driverString = captchaConfig
driver = driverString.ConvertFonts()
captcha := base64Captcha.NewCaptcha(driver, store)

@ -0,0 +1,42 @@
package CaptchaController
import (
"context"
"dsSzxy/Utils/RedisUtil"
"fmt"
"time"
)
var ctx = context.Background()
const CAPTCHA = "captcha:"
type RedisStore struct {
}
// Set set a capt
func (r RedisStore) Set(id string, value string) {
key := CAPTCHA + id
RedisUtil.SET(key, value, time.Minute*2)
}
// Get get a capt
func (r RedisStore) Get(id string, clear bool) string {
key := CAPTCHA + id
val, err := RedisUtil.GET(key)
if err != nil {
fmt.Println(err)
return ""
}
if clear {
RedisUtil.DEL(key)
}
return val
}
// Verify verify a capt
func (r RedisStore) Verify(id, answer string, clear bool) bool {
v := RedisStore{}.Get(id, clear)
return v == answer
}

@ -14,7 +14,7 @@
//得到图形验证码和id
$.ajax({
type: "GET",
url: "/dsSzxy/captchaRelate/GetOne",
url: "/dsSzxy/captchaRelate/getCaptcha",
data: {},
dataType: "JSON",
success: function (result) {
@ -32,7 +32,7 @@
};
$.ajax({
type: "POST",
url: "/dsSzxy/captchaRelate/Verify",
url: "/dsSzxy/captchaRelate/verifyCaptcha",
data: postdata,
dataType: "JSON",
success: function (result) {

Loading…
Cancel
Save