mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-30 00:30:31 +08:00
实现基础的实名认证功能(商业版本专有,开源版本只显示认证状态)
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package userutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ErrUserNotFound = errors.New("not found user")
|
||||
@@ -28,11 +32,59 @@ func InitUser(p *actionutils.ParentAction, userId int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 是否有实名认证
|
||||
hasNewIndividualIdentity, hasNewEnterpriseIdentity, identityTag, err := CheckUserIdentity(p.RPC(), p.AdminContext(), userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.Data["user"] = maps.Map{
|
||||
"id": userId,
|
||||
"fullname": resp.User.Fullname,
|
||||
"username": resp.User.Username,
|
||||
"countAccessKeys": countAccessKeysResp.Count,
|
||||
"id": userId,
|
||||
"fullname": resp.User.Fullname,
|
||||
"username": resp.User.Username,
|
||||
"countAccessKeys": countAccessKeysResp.Count,
|
||||
"hasNewIndividualIdentity": hasNewIndividualIdentity,
|
||||
"hasNewEnterpriseIdentity": hasNewEnterpriseIdentity,
|
||||
"identityTag": identityTag,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckUserIdentity 实名认证信息
|
||||
func CheckUserIdentity(rpcClient *rpc.RPCClient, ctx context.Context, userId int64) (hasNewIndividualIdentity bool, hasNewEnterpriseIdentity bool, identityTag string, err error) {
|
||||
var tags = []string{}
|
||||
|
||||
// 个人
|
||||
individualIdentityResp, err := rpcClient.UserIdentityRPC().FindEnabledUserIdentityWithOrgType(ctx, &pb.FindEnabledUserIdentityWithOrgTypeRequest{
|
||||
UserId: userId,
|
||||
OrgType: userconfigs.UserIdentityOrgTypeIndividual,
|
||||
})
|
||||
if err != nil {
|
||||
return false, false, "", err
|
||||
}
|
||||
var individualIdentity = individualIdentityResp.UserIdentity
|
||||
hasNewIndividualIdentity = individualIdentity != nil && individualIdentity.Status == userconfigs.UserIdentityStatusSubmitted
|
||||
|
||||
if individualIdentity != nil && individualIdentity.Status == userconfigs.UserIdentityStatusVerified {
|
||||
tags = append(tags, "个人")
|
||||
}
|
||||
|
||||
// 企业
|
||||
enterpriseIdentityResp, err := rpcClient.UserIdentityRPC().FindEnabledUserIdentityWithOrgType(ctx, &pb.FindEnabledUserIdentityWithOrgTypeRequest{
|
||||
UserId: userId,
|
||||
OrgType: userconfigs.UserIdentityOrgTypeEnterprise,
|
||||
})
|
||||
if err != nil {
|
||||
return false, false, "", err
|
||||
}
|
||||
var enterpriseIdentity = enterpriseIdentityResp.UserIdentity
|
||||
hasNewEnterpriseIdentity = enterpriseIdentity != nil && enterpriseIdentity.Status == userconfigs.UserIdentityStatusSubmitted
|
||||
|
||||
if enterpriseIdentity != nil && enterpriseIdentity.Status == userconfigs.UserIdentityStatusVerified {
|
||||
tags = append(tags, "企业")
|
||||
}
|
||||
|
||||
identityTag = strings.Join(tags, "+")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user