fix: wechat verify

This commit is contained in:
Rogee
2025-01-10 19:44:24 +08:00
parent ab576706e7
commit 52c17b63bb
13 changed files with 83 additions and 92 deletions

View File

@@ -100,3 +100,14 @@ func (ctl *Controller) Login(ctx fiber.Ctx, code, state, redirectUri string) err
return ctx.Redirect().To(redirectUri)
}
// @Router /MP_verify_:uuid.txt [get]
// @Bind uuid path
func (ctl *Controller) Verify(ctx fiber.Ctx, uuid string) error {
v, err := ctl.wechat.VerifySite(uuid)
if err != nil {
return err
}
return ctx.SendString(v)
}

View File

@@ -40,4 +40,9 @@ func (r *Routes) Register(router fiber.Router) {
QueryParam[string]("redirectUri"),
))
router.Get("/MP_verify_:uuid.txt", Func1(
r.controller.Verify,
PathParam[string]("uuid"),
))
}

View File

@@ -1,6 +1,9 @@
package tenants
import (
"time"
"backend/app/consts"
"backend/providers/jwt"
"backend/providers/otel"
@@ -11,6 +14,7 @@ import (
// @provider
type Controller struct {
svc *Service
jwt *jwt.JWT
log *log.Entry `inject:"false"`
}
@@ -36,6 +40,21 @@ func (c *Controller) Index(ctx fiber.Ctx, tenant string, claim *jwt.Claims) erro
return err
}
if claim.TenantID == nil {
claim.TenantID = &tenantModel.ID
token, err := c.jwt.CreateToken(claim)
if err != nil {
return err
}
ctx.Cookie(&fiber.Cookie{
Name: consts.TokenTypeUser.String(),
Value: token,
Expires: time.Now().Add(6 * time.Hour),
HTTPOnly: true,
})
}
// TODO: render page
return nil
}

View File

@@ -3,6 +3,8 @@ package tenants
import (
"database/sql"
"backend/providers/jwt"
"git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/contracts"
@@ -11,9 +13,11 @@ import (
func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func(
jwt *jwt.JWT,
svc *Service,
) (*Controller, error) {
obj := &Controller{
jwt: jwt,
svc: svc,
}
if err := obj.Prepare(); err != nil {