117 lines
3.0 KiB
Go
117 lines
3.0 KiB
Go
package profile
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
|
"github.com/iwind/TeaGo/actions"
|
|
"github.com/iwind/TeaGo/maps"
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "", "")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
|
userResp, err := this.RPC().UserRPC().FindEnabledUser(this.UserContext(), &pb.FindEnabledUserRequest{UserId: this.UserId()})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var user = userResp.User
|
|
if user == nil {
|
|
this.NotFound("user", this.UserId())
|
|
return
|
|
}
|
|
|
|
this.Data["user"] = maps.Map{
|
|
"fullname": user.Fullname,
|
|
"email": user.Email,
|
|
"verifiedEmail": user.VerifiedEmail,
|
|
"mobile": user.Mobile,
|
|
"verifiedMobile": user.VerifiedMobile,
|
|
"isVerified": user.IsVerified,
|
|
"isRejected": user.IsRejected,
|
|
"rejectReason": user.RejectReason,
|
|
}
|
|
|
|
// 邮箱是否需要激活
|
|
registerConfig, err := configloaders.LoadRegisterConfig()
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
this.Data["emailRequireVerification"] = registerConfig != nil && registerConfig.EmailVerification.IsOn
|
|
|
|
// 现在正等待激活的邮箱
|
|
latestEmailVerificationResp, err := this.RPC().UserEmailVerificationRPC().FindLatestUserEmailVerification(this.UserContext(), &pb.FindLatestUserEmailVerificationRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var latestEmailVerification = latestEmailVerificationResp.UserEmailVerification
|
|
if latestEmailVerification == nil {
|
|
this.Data["latestEmailVerification"] = nil
|
|
} else {
|
|
this.Data["latestEmailVerification"] = maps.Map{
|
|
"email": latestEmailVerification.Email,
|
|
"expiresTime": timeutil.FormatTime("Y-m-d H:i:s", latestEmailVerification.ExpiresAt),
|
|
"isSent": latestEmailVerification.IsSent,
|
|
}
|
|
}
|
|
|
|
// 手机号码是否需要激活
|
|
this.Data["mobileRequireVerification"] = registerConfig != nil && registerConfig.MobileVerification.IsOn
|
|
|
|
this.Show()
|
|
}
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
Fullname string
|
|
Mobile string
|
|
Email string
|
|
|
|
Must *actions.Must
|
|
}) {
|
|
defer this.CreateLogInfo(codes.User_LogUpdateUserProfile)
|
|
|
|
var must = params.Must
|
|
|
|
// 手机号
|
|
must.Field("mobile", params.Mobile).
|
|
Require("请输入手机号").
|
|
Mobile("请输入正确的手机号")
|
|
|
|
// 邮箱
|
|
must.Field("email", params.Email).
|
|
Require("请输入邮箱").
|
|
Email("请输入正确的邮箱")
|
|
|
|
// 全名
|
|
must.Field("fullname", params.Fullname).
|
|
Require("请输入姓名或者公司名称")
|
|
|
|
params.Must.
|
|
Field("fullname", params.Fullname).
|
|
Require("请输入你的姓名")
|
|
|
|
_, err := this.RPC().UserRPC().UpdateUserInfo(this.UserContext(), &pb.UpdateUserInfoRequest{
|
|
UserId: this.UserId(),
|
|
Fullname: params.Fullname,
|
|
Mobile: params.Mobile,
|
|
Email: params.Email,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Success()
|
|
}
|