fix: issues
This commit is contained in:
@@ -7,23 +7,21 @@ import (
|
||||
"quyun/app/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (f *Middlewares) Auth(ctx fiber.Ctx) error {
|
||||
if strings.HasPrefix(ctx.Path(), "/MP_verify_") {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ctx.Path(), "/auth/") {
|
||||
if strings.HasPrefix(ctx.Path(), "/v1/auth/") {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
uu, err := models.Users.GetByID(ctx.Context(), 1)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("failed to get user")
|
||||
return ctx.SendString("NOT OK")
|
||||
}
|
||||
ctx.Locals("user", uu)
|
||||
log.Infof("set ctx user: %d", uu.ID)
|
||||
return ctx.Next()
|
||||
|
||||
fullUrl := string(ctx.Request().URI().FullURI())
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func (f *Middlewares) AuthAdmin(ctx fiber.Ctx) error {
|
||||
if !strings.HasPrefix(ctx.Path(), "/v1/admin") {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
if ctx.Path() == "/v1/admin/auth" {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) DebugMode(ctx fiber.Ctx) error {
|
||||
log.Info("------------------")
|
||||
log.Infof("c.Path: %s", ctx.Path())
|
||||
log.Infof("Request Method: %s", ctx.Method())
|
||||
log.Infof("FullURL: %s", ctx.Request().URI().FullURI())
|
||||
log.Infof("StartPATH: %s", ctx.Params("*"))
|
||||
log.Info("------------------")
|
||||
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
19
backend/app/middlewares/mid_wechat_mp_verify.go
Normal file
19
backend/app/middlewares/mid_wechat_mp_verify.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func (f *Middlewares) WechatMpVerify(ctx fiber.Ctx) error {
|
||||
if !strings.HasPrefix(ctx.Path(), "/MP_verify_") {
|
||||
return ctx.Next()
|
||||
}
|
||||
|
||||
path := strings.Replace(ctx.Path(), "MP_verify_", "", 1)
|
||||
path = strings.Replace(path, ".txt", "", 1)
|
||||
path = strings.Trim(path, "/")
|
||||
|
||||
return ctx.SendString(path)
|
||||
}
|
||||
Reference in New Issue
Block a user