Browse Source

增加 图片验证码功能

main
pixel 5 years ago
parent
commit
c25013ccbf
  1. 19
      QMPlusServer/controller/api/sys_captcha.go
  2. 4
      QMPlusServer/router/sys_base.go
  3. 54
      QMPlusVuePage/src/api/user.js

19
QMPlusServer/controller/api/sys_captcha.go

@ -1,6 +1,7 @@
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)
}

4
QMPlusServer/router/sys_base.go

@ -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
}

54
QMPlusVuePage/src/api/user.js

@ -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",

Loading…
Cancel
Save