2020-12-04 16:00:55 +08:00
|
|
|
package users
|
|
|
|
|
|
|
|
|
|
import (
|
2022-07-24 16:14:38 +08:00
|
|
|
"encoding/json"
|
2020-12-04 16:00:55 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UserAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *UserAction) Init() {
|
|
|
|
|
this.Nav("", "", "index")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *UserAction) RunGet(params struct {
|
|
|
|
|
UserId int64
|
|
|
|
|
}) {
|
|
|
|
|
err := userutils.InitUser(this.Parent(), params.UserId)
|
|
|
|
|
if err != nil {
|
2022-01-05 10:45:28 +08:00
|
|
|
if err == userutils.ErrUserNotFound {
|
|
|
|
|
this.RedirectURL("/users")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 16:00:55 +08:00
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userResp, err := this.RPC().UserRPC().FindEnabledUser(this.AdminContext(), &pb.FindEnabledUserRequest{UserId: params.UserId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-07-24 09:57:26 +08:00
|
|
|
var user = userResp.User
|
2020-12-04 16:00:55 +08:00
|
|
|
if user == nil {
|
|
|
|
|
this.NotFound("user", params.UserId)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 15:49:15 +08:00
|
|
|
var clusterMap maps.Map = nil
|
2020-12-17 17:35:38 +08:00
|
|
|
if user.NodeCluster != nil {
|
2020-12-16 15:49:15 +08:00
|
|
|
clusterMap = maps.Map{
|
2020-12-17 17:35:38 +08:00
|
|
|
"id": user.NodeCluster.Id,
|
|
|
|
|
"name": user.NodeCluster.Name,
|
2020-12-16 15:49:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 19:23:02 +08:00
|
|
|
// AccessKey数量
|
|
|
|
|
countAccessKeyResp, err := this.RPC().UserAccessKeyRPC().CountAllEnabledUserAccessKeys(this.AdminContext(), &pb.CountAllEnabledUserAccessKeysRequest{UserId: params.UserId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
countAccessKeys := countAccessKeyResp.Count
|
|
|
|
|
|
2022-01-05 10:45:28 +08:00
|
|
|
// IP地址
|
|
|
|
|
var registeredRegion = ""
|
|
|
|
|
if len(user.RegisteredIP) > 0 {
|
|
|
|
|
regionResp, err := this.RPC().IPLibraryRPC().LookupIPRegion(this.AdminContext(), &pb.LookupIPRegionRequest{Ip: user.RegisteredIP})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if regionResp.IpRegion != nil {
|
|
|
|
|
registeredRegion = regionResp.IpRegion.Summary
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-24 09:57:26 +08:00
|
|
|
// 是否有实名认证
|
|
|
|
|
hasNewIndividualIdentity, hasNewEnterpriseIdentity, identityTag, err := userutils.CheckUserIdentity(this.RPC(), this.AdminContext(), params.UserId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-24 16:14:38 +08:00
|
|
|
// OTP
|
|
|
|
|
this.Data["otp"] = nil
|
|
|
|
|
if user.OtpLogin != nil && user.OtpLogin.IsOn {
|
|
|
|
|
loginParams := maps.Map{}
|
|
|
|
|
err = json.Unmarshal(user.OtpLogin.ParamsJSON, &loginParams)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.Data["otp"] = maps.Map{
|
|
|
|
|
"isOn": true,
|
|
|
|
|
"params": loginParams,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 16:00:55 +08:00
|
|
|
this.Data["user"] = maps.Map{
|
2022-01-05 10:45:28 +08:00
|
|
|
"id": user.Id,
|
|
|
|
|
"username": user.Username,
|
|
|
|
|
"fullname": user.Fullname,
|
|
|
|
|
"email": user.Email,
|
2022-12-08 20:25:20 +08:00
|
|
|
"verifiedEmail": user.VerifiedEmail,
|
2022-01-05 10:45:28 +08:00
|
|
|
"tel": user.Tel,
|
|
|
|
|
"remark": user.Remark,
|
|
|
|
|
"mobile": user.Mobile,
|
|
|
|
|
"isOn": user.IsOn,
|
|
|
|
|
"cluster": clusterMap,
|
|
|
|
|
"countAccessKeys": countAccessKeys,
|
|
|
|
|
"isRejected": user.IsRejected,
|
|
|
|
|
"rejectReason": user.RejectReason,
|
|
|
|
|
"isVerified": user.IsVerified,
|
|
|
|
|
"registeredIP": user.RegisteredIP,
|
|
|
|
|
"registeredRegion": registeredRegion,
|
2023-02-27 10:46:48 +08:00
|
|
|
"bandwidthAlgo": user.BandwidthAlgo,
|
2022-07-24 09:57:26 +08:00
|
|
|
|
|
|
|
|
// 实名认证
|
|
|
|
|
"hasNewIndividualIdentity": hasNewIndividualIdentity,
|
|
|
|
|
"hasNewEnterpriseIdentity": hasNewEnterpriseIdentity,
|
|
|
|
|
"identityTag": identityTag,
|
2020-12-04 16:00:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|