增加验证码功能
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/controller/servers"
|
||||
"github.com/dchest/captcha"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,20 +12,14 @@ import (
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body modelInterface.PageInfo true "生成验证码"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /base/captcha [post]
|
||||
func Captcha(c *gin.Context) {
|
||||
captchaId := captcha.NewLen(6)
|
||||
if err:= captcha.Server(captcha.StdWidth,captcha.StdHeight);err != nil{
|
||||
servers.ReportFormat(c,true,fmt.Sprintf("验证码获取失败:%v",err),gin.H{})
|
||||
}else{
|
||||
servers.ReportFormat(c,true,"验证码获取成功",gin.H{
|
||||
"captchaId":captchaId,
|
||||
"picPath":"/base/captcha/"+captchaId+".png",
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Tags base
|
||||
@@ -34,7 +27,6 @@ func Captcha(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body modelInterface.PageInfo true "生成验证码图片路径"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /base/captcha/:captchaId [get]
|
||||
func CaptchaImg(c *gin.Context) {
|
||||
|
||||
@@ -25,7 +25,7 @@ func GinCapthcaServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
lang := strings.ToLower(r.FormValue("lang"))
|
||||
download := path.Base(dir) == "download"
|
||||
if Serve(w, r, id, ext, lang, download, captcha.StdWidth, captcha.StdHeight) == captcha.ErrNotFound {
|
||||
if Serve(w, r, id, ext, lang, download, 120, 40) == captcha.ErrNotFound {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user