refactor platform logic modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Package platform 提供平台总后台的同步 HTTP 业务逻辑。
|
||||
// Package common provides shared HTTP and persistence helpers for business logic modules.
|
||||
package common
|
||||
|
||||
import (
|
||||
@@ -12,9 +12,16 @@ import (
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// PasswordHash creates the shared password representation used by account modules.
|
||||
func PasswordHash(password string) (string, error) {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
return string(hash), err
|
||||
}
|
||||
|
||||
// FilterFields keeps only explicitly allowed persistence fields.
|
||||
func FilterFields(values map[string]any, allowedFields []string) gin.H {
|
||||
allowed := make(map[string]struct{}, len(allowedFields))
|
||||
|
||||
21
backend/api/internal/logic/common/operator.go
Normal file
21
backend/api/internal/logic/common/operator.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/middleware"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// PlatformOperator returns the authenticated platform account identity and display name.
|
||||
func PlatformOperator(ctx *gin.Context) (string, string) {
|
||||
claims, err := middleware.ParseAuth(ctx)
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
var account models.PlatformAccount
|
||||
if err := impl.DBService.Select("display_name").Where("identity = ?", claims.Identity).First(&account).Error; err != nil {
|
||||
return claims.Identity, ""
|
||||
}
|
||||
return claims.Identity, account.DisplayName
|
||||
}
|
||||
Reference in New Issue
Block a user