22 lines
687 B
Go
22 lines
687 B
Go
|
|
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
|
||
|
|
}
|