实现基础的实名认证功能(商业版本专有,开源版本只显示认证状态)

This commit is contained in:
刘祥超
2022-07-24 09:57:26 +08:00
parent 40ef3604aa
commit f9dc0d6b54
8 changed files with 163 additions and 5 deletions

View File

@@ -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
}