feat(internal/controllers): 更新 token 生成逻辑以支持用户 ID
- 在多个页面控制器中,更新获取 token 的方法,增加用户 ID 参数 - 修改 TokenService 的 GetToken 方法以接收用户 ID,增强 token 的个性化 - 确保在用户会话中获取 userID,以便为每个用户生成唯一的 token
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"boss/internal/config"
|
||||
"boss/internal/service"
|
||||
"fmt"
|
||||
|
||||
"github.com/beego/beego/v2/core/config/env"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
@@ -69,140 +70,157 @@ func (c *PageAuthController) MerchantPage() {
|
||||
}
|
||||
|
||||
func (c *PageAuthController) MerchantV2Page() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "merchant_v2.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) RechargeAppleAccountPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "apple-card/account.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) RechargeTMallGameAccountPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "t-mall-game/account.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) RechargeTMallGameOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "t-mall-game/recharge-order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) JDOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "jd-card/order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) JDAccountPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "jd-card/account.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) WalmartOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "walmart-card/order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) WalmartGroupPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "walmart-card/group.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) WalmartAccountPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "walmart-card/account.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) CTripOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "c-trip-card/order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) CTripAccountPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "c-trip-card/account.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) RechargeTMallGameShopOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "t-mall-game/recharge-shop-order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) RechargeTMallGameSummaryPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "t-mall-game/summary.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) OrderSummary() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.Data["roadUid"] = c.GetString("roadUid")
|
||||
c.TplName = "order_summary.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) UserManagement() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
// 获取当前时间的时间戳
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.Data["roadUid"] = c.GetString("roadUid")
|
||||
c.TplName = "user/management.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) RechargeAppleOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "apple-card/recharge-order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) StealOrderPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "apple-card/steal-user-management.html"
|
||||
}
|
||||
@@ -283,33 +301,37 @@ func (c *PageAuthController) AgentProfitPage() {
|
||||
}
|
||||
|
||||
func (c *PageAuthController) StealRule() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "merchant/steal-rule.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) JdCardCkAccount() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "jd-ck/account.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) JdCardCkOrder() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "jd-ck/order.html"
|
||||
}
|
||||
|
||||
func (c *PageAuthController) DashboardPage() {
|
||||
userID, _ := c.GetSession("userID").(string)
|
||||
ctx := c.Ctx.Request.Context()
|
||||
tokenService := service.NewTokenService()
|
||||
c.Data["token"] = tokenService.GetToken(ctx)
|
||||
c.Data["token"] = tokenService.GetToken(ctx, userID)
|
||||
c.Data["portalHost"] = config.GetPortalHost()
|
||||
c.TplName = "dashboard/dashboard.html"
|
||||
}
|
||||
|
||||
@@ -13,11 +13,15 @@ import (
|
||||
type TokenService struct {
|
||||
}
|
||||
|
||||
func (t *TokenService) GetToken(ctx context.Context) (token string) {
|
||||
func (t *TokenService) GetToken(ctx context.Context, userId string) (token string) {
|
||||
tokenStruct := struct {
|
||||
CurrentTime int64 `json:"currentTime"`
|
||||
CurrentTime int64 `json:"currentTime"`
|
||||
UserId string `json:"userId"`
|
||||
UserAuth string `json:"userAuth"`
|
||||
}{
|
||||
CurrentTime: time.Now().Unix(),
|
||||
UserAuth: "admin",
|
||||
UserId: userId,
|
||||
}
|
||||
tokenBytes, _ := json.Marshal(tokenStruct)
|
||||
secretCfg := config.GetSecret()
|
||||
|
||||
Reference in New Issue
Block a user