fix: issues
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"backend/pkg/pg"
|
||||
@@ -14,9 +17,6 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("END")
|
||||
|
||||
// 如果请求存在 Authorization 头,则跳过
|
||||
if len(c.GetReqHeaders()["Authorization"]) != 0 {
|
||||
return c.Next()
|
||||
@@ -81,6 +81,13 @@ func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
|
||||
return errors.Wrap(err, "failed to create token")
|
||||
}
|
||||
|
||||
// TODO: send html with jwt token
|
||||
return c.SendString(jwtToken)
|
||||
b, err := os.ReadFile(filepath.Join(f.storagePath.Asset, "index.html"))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read file")
|
||||
}
|
||||
|
||||
html := strings.ReplaceAll(string(b), "{{JWT}}", jwtToken)
|
||||
|
||||
c.Set("Content-Type", "text/html")
|
||||
return c.SendString(html)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatSilentAuth").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatSilentAuth").Debug("END")
|
||||
|
||||
// if cookie not exists key "openid", then redirect to the wechat auth page
|
||||
token := c.GetReqHeaders()["Authorization"]
|
||||
if len(token) != 0 {
|
||||
|
||||
@@ -7,9 +7,6 @@ import (
|
||||
|
||||
// 此方法用于微信首次接入时的数据验证
|
||||
func (f *Middlewares) WeChatVerify(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatVerify").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatVerify").Debug("END")
|
||||
|
||||
// get the query parameters
|
||||
signature := c.Query("signature")
|
||||
timestamp := c.Query("timestamp")
|
||||
|
||||
@@ -2,12 +2,9 @@ package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (f *Middlewares) DebugMode(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.DebugMode").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.DebugMode").Debug("END")
|
||||
// fullURI := c.Request().URI().FullURI()
|
||||
// host := c.BaseURL()
|
||||
// fmt.Println(strings.Split(c.Path(), "/"))
|
||||
|
||||
@@ -8,9 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.ProcessResponse").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.ProcessResponse").Debug("END")
|
||||
|
||||
err := c.Next()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("process response error")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"backend/modules/users"
|
||||
"backend/providers/app"
|
||||
"backend/providers/jwt"
|
||||
"backend/providers/storage"
|
||||
"backend/providers/wechat"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -11,11 +12,12 @@ import (
|
||||
|
||||
// @provider
|
||||
type Middlewares struct {
|
||||
app *app.Config
|
||||
client *wechat.Client
|
||||
userSvc *users.Service
|
||||
jwt *jwt.JWT
|
||||
log *log.Entry `inject:"false"`
|
||||
app *app.Config
|
||||
storagePath *storage.Config
|
||||
client *wechat.Client
|
||||
userSvc *users.Service
|
||||
jwt *jwt.JWT
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
func (f *Middlewares) Prepare() error {
|
||||
|
||||
Reference in New Issue
Block a user