mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-14 20:30:25 +08:00
实现基础的实名认证功能(商业版本专有,开源版本只显示认证状态)
This commit is contained in:
@@ -424,6 +424,10 @@ func (this *RPCClient) UserAccessKeyRPC() pb.UserAccessKeyServiceClient {
|
|||||||
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserIdentityRPC() pb.UserIdentityServiceClient {
|
||||||
|
return pb.NewUserIdentityServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) LoginRPC() pb.LoginServiceClient {
|
func (this *RPCClient) LoginRPC() pb.LoginServiceClient {
|
||||||
return pb.NewLoginServiceClient(this.pickConn())
|
return pb.NewLoginServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|||||||
62
internal/web/actions/default/files/file.go
Normal file
62
internal/web/actions/default/files/file.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"mime"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *FileAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *FileAction) RunGet(params struct {
|
||||||
|
FileId int64
|
||||||
|
}) {
|
||||||
|
fileResp, err := this.RPC().FileRPC().FindEnabledFile(this.AdminContext(), &pb.FindEnabledFileRequest{FileId: params.FileId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var file = fileResp.File
|
||||||
|
if file == nil {
|
||||||
|
this.NotFound("File", params.FileId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkIdsResp, err := this.RPC().FileChunkRPC().FindAllFileChunkIds(this.AdminContext(), &pb.FindAllFileChunkIdsRequest{FileId: file.Id})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.AddHeader("Content-Length", types.String(file.Size))
|
||||||
|
if len(file.MimeType) > 0 {
|
||||||
|
this.AddHeader("Content-Type", file.MimeType)
|
||||||
|
} else if len(file.Filename) > 0 {
|
||||||
|
var ext = filepath.Ext(file.Filename)
|
||||||
|
var mimeType = mime.TypeByExtension(ext)
|
||||||
|
this.AddHeader("Content-Type", mimeType)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, chunkId := range chunkIdsResp.FileChunkIds {
|
||||||
|
chunkResp, err := this.RPC().FileChunkRPC().DownloadFileChunk(this.AdminContext(), &pb.DownloadFileChunkRequest{FileChunkId: chunkId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if chunkResp.FileChunk == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.Write(chunkResp.FileChunk.Data)
|
||||||
|
}
|
||||||
|
}
|
||||||
14
internal/web/actions/default/files/init.go
Normal file
14
internal/web/actions/default/files/init.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package files
|
||||||
|
|
||||||
|
import "github.com/iwind/TeaGo"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Prefix("/files").
|
||||||
|
Get("/file", new(FileAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -44,6 +44,13 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
countAccessKeys := countAccessKeyResp.Count
|
countAccessKeys := countAccessKeyResp.Count
|
||||||
|
|
||||||
|
// 是否有实名认证
|
||||||
|
hasNewIndividualIdentity, hasNewEnterpriseIdentity, identityTag, err := userutils.CheckUserIdentity(this.RPC(), this.AdminContext(), params.UserId)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["user"] = maps.Map{
|
this.Data["user"] = maps.Map{
|
||||||
"id": user.Id,
|
"id": user.Id,
|
||||||
"username": user.Username,
|
"username": user.Username,
|
||||||
@@ -54,6 +61,11 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
"mobile": user.Mobile,
|
"mobile": user.Mobile,
|
||||||
"isOn": user.IsOn,
|
"isOn": user.IsOn,
|
||||||
"countAccessKeys": countAccessKeys,
|
"countAccessKeys": countAccessKeys,
|
||||||
|
|
||||||
|
// 实名认证
|
||||||
|
"hasNewIndividualIdentity": hasNewIndividualIdentity,
|
||||||
|
"hasNewEnterpriseIdentity": hasNewEnterpriseIdentity,
|
||||||
|
"identityTag": identityTag,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Data["clusterId"] = 0
|
this.Data["clusterId"] = 0
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (this *UserAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user := userResp.User
|
var user = userResp.User
|
||||||
if user == nil {
|
if user == nil {
|
||||||
this.NotFound("user", params.UserId)
|
this.NotFound("user", params.UserId)
|
||||||
return
|
return
|
||||||
@@ -69,6 +69,13 @@ func (this *UserAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否有实名认证
|
||||||
|
hasNewIndividualIdentity, hasNewEnterpriseIdentity, identityTag, err := userutils.CheckUserIdentity(this.RPC(), this.AdminContext(), params.UserId)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["user"] = maps.Map{
|
this.Data["user"] = maps.Map{
|
||||||
"id": user.Id,
|
"id": user.Id,
|
||||||
"username": user.Username,
|
"username": user.Username,
|
||||||
@@ -85,6 +92,11 @@ func (this *UserAction) RunGet(params struct {
|
|||||||
"isVerified": user.IsVerified,
|
"isVerified": user.IsVerified,
|
||||||
"registeredIP": user.RegisteredIP,
|
"registeredIP": user.RegisteredIP,
|
||||||
"registeredRegion": registeredRegion,
|
"registeredRegion": registeredRegion,
|
||||||
|
|
||||||
|
// 实名认证
|
||||||
|
"hasNewIndividualIdentity": hasNewIndividualIdentity,
|
||||||
|
"hasNewEnterpriseIdentity": hasNewEnterpriseIdentity,
|
||||||
|
"identityTag": identityTag,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package userutils
|
package userutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrUserNotFound = errors.New("not found user")
|
var ErrUserNotFound = errors.New("not found user")
|
||||||
@@ -28,11 +32,59 @@ func InitUser(p *actionutils.ParentAction, userId int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否有实名认证
|
||||||
|
hasNewIndividualIdentity, hasNewEnterpriseIdentity, identityTag, err := CheckUserIdentity(p.RPC(), p.AdminContext(), userId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
p.Data["user"] = maps.Map{
|
p.Data["user"] = maps.Map{
|
||||||
"id": userId,
|
"id": userId,
|
||||||
"fullname": resp.User.Fullname,
|
"fullname": resp.User.Fullname,
|
||||||
"username": resp.User.Username,
|
"username": resp.User.Username,
|
||||||
"countAccessKeys": countAccessKeysResp.Count,
|
"countAccessKeys": countAccessKeysResp.Count,
|
||||||
|
"hasNewIndividualIdentity": hasNewIndividualIdentity,
|
||||||
|
"hasNewEnterpriseIdentity": hasNewEnterpriseIdentity,
|
||||||
|
"identityTag": identityTag,
|
||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package web
|
|||||||
import (
|
import (
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/tasks"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/tasks"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/about"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/about"
|
||||||
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/files"
|
||||||
|
|
||||||
// 系统用户
|
// 系统用户
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins"
|
||||||
|
|||||||
@@ -4,5 +4,6 @@
|
|||||||
<menu-item :href="'/users/user?userId=' + user.id" code="index">{{user.fullname}} <span class="small">({{user.username}})</span></menu-item>
|
<menu-item :href="'/users/user?userId=' + user.id" code="index">{{user.fullname}} <span class="small">({{user.username}})</span></menu-item>
|
||||||
<menu-item :href="'/users/update?userId=' + user.id" code="update">修改</menu-item>
|
<menu-item :href="'/users/update?userId=' + user.id" code="update">修改</menu-item>
|
||||||
<menu-item :href="'/users/features?userId=' + user.id" code="feature">功能</menu-item>
|
<menu-item :href="'/users/features?userId=' + user.id" code="feature">功能</menu-item>
|
||||||
|
<menu-item :href="'/users/identity?userId=' + user.id" code="identity" v-if="teaIsPlus">实名认证<span v-if="user.hasNewIndividualIdentity || user.hasNewEnterpriseIdentity" class="red small">(待审核)</span><span v-if="user.identityTag != null && user.identityTag.length > 0" class="green">({{user.identityTag}})</span></menu-item>
|
||||||
<menu-item :href="'/users/accessKeys?userId=' + user.id" code="accessKey">API AccessKey({{user.countAccessKeys}})</menu-item>
|
<menu-item :href="'/users/accessKeys?userId=' + user.id" code="accessKey">API AccessKey({{user.countAccessKeys}})</menu-item>
|
||||||
</first-menu>
|
</first-menu>
|
||||||
Reference in New Issue
Block a user