This commit is contained in:
lwl0608 2024-12-04 17:08:38 +08:00
commit dc7463b22e
4 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package controller
import (
"github.com/gin-gonic/gin"
"service/library/apollo"
"service/library/logger"
)
func ColdConfigHandler(ctx *gin.Context) {
shareRedirectUrl, err := apollo.GetStringValue("share_redirect_url", apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("apollo.GetStringValue fail, key: %v, err: %v", "share_redirect_url", err)
}
data := map[string]any{
"share_redirect_url": shareRedirectUrl,
}
ReplyOk(ctx, data)
}

View File

@ -335,6 +335,9 @@ func Init(r *gin.Engine) {
apiShareGroup := r.Group("/api/share", PrepareToC())
apiShareGroup.POST("zone_url", GetZoneShareUrl)
apiConfigGroup := r.Group("/api/config", PrepareToC())
apiConfigGroup.POST("cold_config", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), ColdConfigHandler)
// =============================== 以下是服务,只允许内网调用 ===============================
// op相关直接调用服务不调用gateway

View File

@ -159,6 +159,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
// 1.业务校验
login, account, vericode, ec = s.ApiLoginByVeriCodeBusinessValidate(ctx, req)
logger.Info("login business validation finished...")
// 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息
if req.Channel == "h5" {
@ -184,6 +185,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
ec = errcode.ErrCodeLoginSrvFail
return
}
logger.Info("veri code delete finished...")
// 4.让已登录的用户强制下线
if account.GetRole() == consts.User {
@ -192,6 +194,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
ec = errcode.ErrCodeLoginSrvOk
return
}
logger.Info("logout finished...")
}
// 5.生成token
@ -205,6 +208,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
logger.Error("ApiGenerate failed, err: %v", err)
return
}
logger.Info("token generated...")
// 6.更新登录状态
if err = _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
@ -217,6 +221,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
logger.Error("ApiUpdate failed, err: %v", err)
return
}
logger.Info("login info updated...")
// 7.组装返回信息
isEnabled = util.DerefInt64(login.IsEnabled)
@ -225,6 +230,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB
wallet, _ := _DefaultVas.CheckWalletExist(ctx, nil, util.DerefInt64(accountVO.Mid))
accountVO.CopyWallet(wallet)
logger.Info("login finished...")
return
}

View File

@ -231,6 +231,7 @@ func (l *LoginBusinessValidator) EnsureVeriCodeIsCorrect(fun func(*gin.Context,
l.oplist = append(l.oplist, func() {
if l.vericode.VeriCode != l.vericodeAccessor.GetVeriCode() {
logger.Error("Wrong verification code")
logger.Error("should be %v, but get %v", l.vericode.VeriCode, l.vericodeAccessor.GetVeriCode())
// 如果不是首次登录,则错误次数+1
if l.login != nil {