fix issues
This commit is contained in:
@@ -20,7 +20,7 @@ func init() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(controller.NewController); err != nil {
|
||||
if err := container.Container.Provide(controller.NewCaptchaController); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
44
modules/system/controller/captcha.go
Executable file
44
modules/system/controller/captcha.go
Executable file
@@ -0,0 +1,44 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"atom/modules/system/dto"
|
||||
"atom/providers/config"
|
||||
"errors"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
)
|
||||
|
||||
type CaptchaController interface {
|
||||
Show(*gin.Context) (dto.SysCaptchaResponse, error)
|
||||
}
|
||||
|
||||
type captchaControllerImpl struct {
|
||||
conf *config.Config
|
||||
}
|
||||
|
||||
func NewCaptchaController(conf *config.Config) CaptchaController {
|
||||
return &captchaControllerImpl{conf: conf}
|
||||
}
|
||||
|
||||
func (c *captchaControllerImpl) Show(ctx *gin.Context) (dto.SysCaptchaResponse, error) {
|
||||
// 判断验证码是否开启
|
||||
var store = base64Captcha.DefaultMemStore
|
||||
|
||||
// 字符,公式,验证码配置
|
||||
// 生成默认数字的driver
|
||||
driver := base64Captcha.NewDriverDigit(c.conf.Captcha.ImgHeight, c.conf.Captcha.ImgWidth, c.conf.Captcha.KeyLong, 0.7, 80)
|
||||
// cp := base64Captcha.NewCaptcha(driver, store.UseWithCtx(c)) // v8下使用redis
|
||||
cp := base64Captcha.NewCaptcha(driver, store)
|
||||
id, b64s, err := cp.Generate()
|
||||
if err != nil {
|
||||
return dto.SysCaptchaResponse{}, errors.New("验证码获取失败")
|
||||
}
|
||||
|
||||
return dto.SysCaptchaResponse{
|
||||
CaptchaId: id,
|
||||
PicPath: b64s,
|
||||
CaptchaLength: c.conf.Captcha.KeyLong,
|
||||
OpenCaptcha: c.conf.Captcha.OpenCaptcha != 0,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"atom/modules/system/dao"
|
||||
"atom/modules/system/dto"
|
||||
"atom/modules/system/service"
|
||||
"atom/providers/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Controller interface {
|
||||
GetName(*gin.Context) (dto.Name, error)
|
||||
}
|
||||
|
||||
type ControllerImpl struct {
|
||||
Conf *config.Config
|
||||
svc service.SystemService
|
||||
}
|
||||
|
||||
func NewController(Conf *config.Config, dao dao.Dao, svc service.SystemService) Controller {
|
||||
return &ControllerImpl{Conf: Conf, svc: svc}
|
||||
}
|
||||
|
||||
func (c *ControllerImpl) GetName(ctx *gin.Context) (dto.Name, error) {
|
||||
return c.svc.GetName(ctx)
|
||||
}
|
||||
8
modules/system/dto/captcha.go
Normal file
8
modules/system/dto/captcha.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package dto
|
||||
|
||||
type SysCaptchaResponse struct {
|
||||
CaptchaId string `json:"captcha_id,omitempty"`
|
||||
PicPath string `json:"pic_path,omitempty"`
|
||||
CaptchaLength int `json:"captcha_length,omitempty"`
|
||||
OpenCaptcha bool `json:"open_captcha,omitempty"`
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package dto
|
||||
|
||||
type Name struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
)
|
||||
|
||||
type Route struct {
|
||||
controller controller.Controller
|
||||
svc *http.Service
|
||||
captcha controller.CaptchaController
|
||||
svc *http.Service
|
||||
}
|
||||
|
||||
func NewRoute(c controller.Controller, svc *http.Service) contracts.Route {
|
||||
return &Route{controller: c, svc: svc}
|
||||
func NewRoute(captcha controller.CaptchaController, svc *http.Service) contracts.Route {
|
||||
return &Route{captcha: captcha, svc: svc}
|
||||
}
|
||||
|
||||
func (r *Route) Register() {
|
||||
r.svc.Engine.GET("/name", gen.DataFunc(r.controller.GetName))
|
||||
r.svc.Engine.GET("/captcha", gen.DataFunc(r.captcha.GetName))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user