浏览代码

账号体系的兼容版本

dcsunny 4 年之前
父节点
当前提交
db1e91a3b7
共有 2 个文件被更改,包括 21 次插入2 次删除
  1. 3 2
      common/context.go
  2. 18 0
      http/param/auth.go

+ 3 - 2
common/context.go

@@ -6,8 +6,9 @@ import (
 	context2 "git.ikuban.com/server/kratos-utils/http/context"
 )
 
-func NewContext(userID int64) context.Context {
+func NewContext(accountID int64) context.Context {
 	ctx := context.Background()
-	ctx = context2.AppendToContext(ctx, "user_id", userID)
+	ctx = context2.AppendToContext(ctx, "user_id", accountID)
+	ctx = context2.AppendToContext(ctx, "account_id", accountID)
 	return ctx
 }

+ 18 - 0
http/param/auth.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 )
 
+//GetUserID  临时的,account 新版本为accountid
 func GetUserID(c context.Context) int64 {
 	userID := c.Value("user_id")
 	if _, ok := userID.(int64); ok {
@@ -13,6 +14,23 @@ func GetUserID(c context.Context) int64 {
 	return 0
 }
 
+func GetAccountID(c context.Context) int64 {
+	accountID := c.Value("account_id")
+	if _, ok := accountID.(int64); ok {
+		return accountID.(int64)
+	}
+	return 0
+}
+
+//GetMemberID  临时的,account 新版本为userid
+func GetMemberID(c context.Context) int64 {
+	userID := c.Value("mem_id")
+	if _, ok := userID.(int64); ok {
+		return userID.(int64)
+	}
+	return 0
+}
+
 func GetAuthToken(c context.Context) string {
 	token := c.Value("token")
 	if _, ok := token.(string); ok {