From 3fef23d3c3eb18d31aa2edb797d1689978f27c59 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 25 Apr 2024 10:01:34 +0800 Subject: [PATCH] by Robin at 20240425 --- api/errcode/errcode.go | 2 +- app/mix/dao/mongo.go | 19 ++++++++++++++++++- app/mix/service/apiservice.go | 9 ++++++--- app/mix/service/cronservice.go | 1 + app/mix/service/logic/login.go | 10 ++++++++++ app/mix/service/xxljob_tasks.go | 11 +++++++++++ .../xxl-job/xxl-job-executor-go/executor.go | 1 - 7 files changed, 47 insertions(+), 6 deletions(-) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index c134231f..e907c631 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -32,7 +32,7 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeLoginWrongPswd: "登录密码错误", ErrCodeLoginWrongVeriCode: "验证码错误", ErrCodeLoginVeriCodeExpired: "验证码已过期", - ErrCodeLoginAcctLocked: "登录账户尝试爆破登录,已被锁定", + ErrCodeLoginAcctLocked: "账户已锁定,请明日再试", ErrCodeLoginAcctBanned: "登录账户已被封禁", ErrCodeLoginAcctNotEnabled: "登录账户未设置密码,请使用验证码登录", ErrCodeLoginNoChangeInAPswdReset: "新旧密码相同", diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index dbaea8e6..b746180a 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -997,7 +997,24 @@ func (m *Mongo) UpdateLoginByMid(ctx *gin.Context, login *dbstruct.Login, mid in return err } -// 登录表 +func (m *Mongo) ClearLoginWrongPswdTimes(ctx *gin.Context) error { + col := m.getColLogin() + + up := qmgo.M{ + "$set": qmgo.M{ + "wrong_pswd_times": int64(0), + }, + } + + filter := qmgo.M{ + "del_flag": 0, + } + + _, err := col.UpdateAll(ctx, filter, up) + return err +} + +// 登录历史表 func (m *Mongo) CreateLoginHis(ctx *gin.Context, logins []*dbstruct.Login) error { col := m.getColLoginHis() _, err := col.InsertMany(ctx, logins) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 2b5a201b..c06365da 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2823,10 +2823,13 @@ func (s *Service) ApiGetZoneMomentStatisticsByCreaterMid(ctx *gin.Context, req * } // 免费贴个数 - freeCount := zoneMomentCreateTimes.FreeCreateTimes - + freeCount := int64(0) // 付费贴个数 - paidCount := zoneMomentCreateTimes.PaidCreateTimes + paidCount := int64(0) + if zoneMomentCreateTimes != nil { + freeCount = zoneMomentCreateTimes.FreeCreateTimes + paidCount = zoneMomentCreateTimes.PaidCreateTimes + } // 审核未通过个数 rejectedCount, err := _DefaultZoneMoment.OpCountByMidAndStatus(ctx, req.BaseRequest.Mid, consts.ZoneMoment_Private) diff --git a/app/mix/service/cronservice.go b/app/mix/service/cronservice.go index 8af0b457..0b08d1ee 100644 --- a/app/mix/service/cronservice.go +++ b/app/mix/service/cronservice.go @@ -58,6 +58,7 @@ func (s *CronService) Init(c any) (err error) { exec.RegTask("cancel_account_at_due_time", s.CancelAccountsAtDueTime) exec.RegTask("reload_moment_recomm_list", s.ReloadMomentRecommList) exec.RegTask("clear_zone_moment_create_times", s.ClearZoneMomentCreateTimes) + exec.RegTask("clear_wrong_pswd_times", s.ClearWrongPswdTimes) exec.LogHandler(customLogHandle) //注册任务handler diff --git a/app/mix/service/logic/login.go b/app/mix/service/logic/login.go index 2c08b3ee..f72eb7c7 100644 --- a/app/mix/service/logic/login.go +++ b/app/mix/service/logic/login.go @@ -119,6 +119,16 @@ func (p *Login) OpHandleWrongPswd(ctx *gin.Context, login *dbstruct.Login) error return nil } +// 抹去密码错误次数 +func (p *Login) OpClearWrongPswdTimes(ctx *gin.Context) error { + err := p.store.ClearLoginWrongPswdTimes(ctx) + if err != nil { + logger.Error("Clear wrong password times failed : %v", err) + return err + } + return err +} + // 产生原始登录信息 func (p *Login) GenerateOriginalLogin() *dbstruct.Login { originalLogin := &dbstruct.Login{ diff --git a/app/mix/service/xxljob_tasks.go b/app/mix/service/xxljob_tasks.go index e723925d..09b00274 100644 --- a/app/mix/service/xxljob_tasks.go +++ b/app/mix/service/xxljob_tasks.go @@ -434,3 +434,14 @@ func (s *CronService) ClearZoneMomentCreateTimes(ctx context.Context, param *xxl logger.Info("zone_moment_create_times collection has been cleared") return "zone_moment_create_times collection has been cleared" } + +func (s *CronService) ClearWrongPswdTimes(ctx context.Context, param *xxl.RunReq) (msg string) { + logger.Info("task %v param: %v log_id: %v", param.ExecutorHandler, param.ExecutorParams, xxl.Int64ToStr(param.LogID)) + logger.Info("Clearing wrong_pswd_times...") + if err := _DefaultLogin.OpClearWrongPswdTimes(&gin.Context{}); err != nil { + logger.Error("Clear wrong_pswd_times fail: %v", err) + return fmt.Sprintf("Clear wrong_pswd_times fail: %v", err) + } + logger.Info("wrong_pswd_times has been cleared") + return "wrong_pswd_times has been cleared" +} diff --git a/vendor/github.com/xxl-job/xxl-job-executor-go/executor.go b/vendor/github.com/xxl-job/xxl-job-executor-go/executor.go index 83b59f12..f92f640f 100644 --- a/vendor/github.com/xxl-job/xxl-job-executor-go/executor.go +++ b/vendor/github.com/xxl-job/xxl-job-executor-go/executor.go @@ -288,7 +288,6 @@ func (e *executor) registry() { e.log.Error("执行器注册失败3:" + string(body)) return } - e.log.Info("执行器注册成功:" + string(body)) }() }