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

增加 图片验证码功能

上级 cfeac439
package api
import (
"fmt"
"gin-vue-admin/controller/servers"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
......@@ -16,12 +17,16 @@ import (
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha [post]
func Captcha(c *gin.Context) {
id := captcha.NewLen(6)
captcha.Server(captcha.StdWidth,captcha.StdHeight)
servers.ReportFormat(c,true,"test",gin.H{
"id":id,
"picPath":"/base/captcha/"+id+".png",
})
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
......@@ -31,7 +36,7 @@ func Captcha(c *gin.Context) {
// @Produce application/json
// @Param data body modelInterface.PageInfo true "生成验证码图片路径"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /base/captcha/:id [get]
// @Router /base/captcha/:captchaId [get]
func CaptchaImg(c *gin.Context) {
servers.GinCapthcaServeHTTP(c.Writer, c.Request)
}
......
......@@ -10,8 +10,8 @@ func InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
{
BaseRouter.POST("regist", api.Regist)
BaseRouter.POST("login", api.Login)
BaseRouter.GET("captcha",api.Captcha)
BaseRouter.GET("/captcha/:id",api.CaptchaImg)
BaseRouter.POST("captcha",api.Captcha)
BaseRouter.GET("captcha/:captchaId",api.CaptchaImg)
}
return BaseRouter
}
......@@ -12,36 +12,48 @@ export const login = (data) => {
})
}
// @Summary 用户注册
// @Summary 获取验证码
// @Produce application/json
// @Param data body {username:"string",password:"string"}
// @Router /base/resige [post]
export const regist = (data) => {
// @Router /base/captcha [post]
export const captcha = (data) => {
return service({
url: "/base/regist",
url: "/base/captcha",
method: 'post',
data: data
})
}
// @Summary 修改密码
// @Summary 用户注册
// @Produce application/json
// @Param data body {username:"string",password:"string",newPassword:"string"}
// @Router /user/changePassword [post]
// @Param data body {username:"string",password:"string"}
// @Router /base/resige [post]
export const regist = (data) => {
return service({
url: "/base/regist",
method: 'post',
data: data
})
}
// @Summary 修改密码
// @Produce application/json
// @Param data body {username:"string",password:"string",newPassword:"string"}
// @Router /user/changePassword [post]
export const changePassword = (data) => {
return service({
url: "/user/changePassword",
method: 'post',
data: data
})
}
// @Tags User
// @Summary 分页获取用户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body modelInterface.PageInfo true "分页获取用户列表"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getUserList [post]
return service({
url: "/user/changePassword",
method: 'post',
data: data
})
}
// @Tags User
// @Summary 分页获取用户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body modelInterface.PageInfo true "分页获取用户列表"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getUserList [post]
export const getUserList = (data) => {
return service({
url: "/user/getUserList",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册