提交 d1c1f73e 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

增加验证码功能

上级 c25013cc
package api package api
import ( import (
"fmt"
"gin-vue-admin/controller/servers" "gin-vue-admin/controller/servers"
"github.com/dchest/captcha" "github.com/dchest/captcha"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
...@@ -13,20 +12,14 @@ import ( ...@@ -13,20 +12,14 @@ import (
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body modelInterface.PageInfo true "生成验证码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha [post] // @Router /base/captcha [post]
func Captcha(c *gin.Context) { func Captcha(c *gin.Context) {
captchaId := captcha.NewLen(6) 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{ servers.ReportFormat(c,true,"验证码获取成功",gin.H{
"captchaId":captchaId, "captchaId":captchaId,
"picPath":"/base/captcha/"+captchaId+".png", "picPath":"/base/captcha/"+captchaId+".png",
}) })
}
} }
// @Tags base // @Tags base
...@@ -34,7 +27,6 @@ func Captcha(c *gin.Context) { ...@@ -34,7 +27,6 @@ func Captcha(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body modelInterface.PageInfo true "生成验证码图片路径"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha/:captchaId [get] // @Router /base/captcha/:captchaId [get]
func CaptchaImg(c *gin.Context) { func CaptchaImg(c *gin.Context) {
......
...@@ -25,7 +25,7 @@ func GinCapthcaServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -25,7 +25,7 @@ func GinCapthcaServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
lang := strings.ToLower(r.FormValue("lang")) lang := strings.ToLower(r.FormValue("lang"))
download := path.Base(dir) == "download" 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) http.NotFound(w, r)
} }
} }
......
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // This file was generated by swaggo/swag at
// 2020-03-17 14:07:14.3860547 +0800 CST m=+0.077792301 // 2020-03-17 15:18:08.5115326 +0800 CST m=+0.098737601
package docs package docs
...@@ -421,18 +421,6 @@ var doc = `{ ...@@ -421,18 +421,6 @@ var doc = `{
"base" "base"
], ],
"summary": "生成验证码", "summary": "生成验证码",
"parameters": [
{
"description": "生成验证码",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/modelInterface.PageInfo"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
...@@ -460,18 +448,6 @@ var doc = `{ ...@@ -460,18 +448,6 @@ var doc = `{
"base" "base"
], ],
"summary": "生成验证码图片路径", "summary": "生成验证码图片路径",
"parameters": [
{
"description": "生成验证码图片路径",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/modelInterface.PageInfo"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
......
...@@ -404,18 +404,6 @@ ...@@ -404,18 +404,6 @@
"base" "base"
], ],
"summary": "生成验证码", "summary": "生成验证码",
"parameters": [
{
"description": "生成验证码",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/modelInterface.PageInfo"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
...@@ -443,18 +431,6 @@ ...@@ -443,18 +431,6 @@
"base" "base"
], ],
"summary": "生成验证码图片路径", "summary": "生成验证码图片路径",
"parameters": [
{
"description": "生成验证码图片路径",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/modelInterface.PageInfo"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
......
...@@ -544,14 +544,6 @@ paths: ...@@ -544,14 +544,6 @@ paths:
post: post:
consumes: consumes:
- application/json - application/json
parameters:
- description: 生成验证码
in: body
name: data
required: true
schema:
$ref: '#/definitions/modelInterface.PageInfo'
type: object
produces: produces:
- application/json - application/json
responses: responses:
...@@ -568,14 +560,6 @@ paths: ...@@ -568,14 +560,6 @@ paths:
get: get:
consumes: consumes:
- application/json - application/json
parameters:
- description: 生成验证码图片路径
in: body
name: data
required: true
schema:
$ref: '#/definitions/modelInterface.PageInfo'
type: object
produces: produces:
- application/json - application/json
responses: responses:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册