Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update captcha

aichy126b6a85b06abd7
diff --git a/internal/entity/captcha_entity.go b/internal/entity/captcha_entity.go
index d8520925..bb7c39ce 100644
--- a/internal/entity/captcha_entity.go
+++ b/internal/entity/captcha_entity.go
@@ -16,6 +16,7 @@ const (
)
type ActionRecordInfo struct {
- LastTime int `json:"last_time"`
- Num int `json:"num"`
+ LastTime int `json:"last_time"`
+ Num int `json:"num"`
+ Config string `json:"config"`
}
diff --git a/internal/repo/captcha/captcha.go b/internal/repo/captcha/captcha.go
index c7ea9d07..1f504e33 100644
--- a/internal/repo/captcha/captcha.go
+++ b/internal/repo/captcha/captcha.go
@@ -27,7 +27,7 @@ func NewCaptchaRepo(data *data.Data) action.CaptchaRepo {
}
}
-func (cr *captchaRepo) SetActionType(ctx context.Context, unit, actionType string, amount int) (err error) {
+func (cr *captchaRepo) SetActionType(ctx context.Context, unit, actionType, config string, amount int) (err error) {
now := time.Now()
cacheKey := fmt.Sprintf("ActionRecord:%s@%s@%s", unit, actionType, now.Format("2006-1-02"))
value := &entity.ActionRecordInfo{}
diff --git a/internal/repo/repo_test/captcha_test.go b/internal/repo/repo_test/captcha_test.go
index 74353a8e..fb02c153 100644
--- a/internal/repo/repo_test/captcha_test.go
+++ b/internal/repo/repo_test/captcha_test.go
@@ -16,7 +16,7 @@ var (
func Test_captchaRepo_DelActionType(t *testing.T) {
captchaRepo := captcha.NewCaptchaRepo(testDataSource)
- err := captchaRepo.SetActionType(context.TODO(), ip, actionType, amount)
+ err := captchaRepo.SetActionType(context.TODO(), ip, actionType, "", amount)
assert.NoError(t, err)
gotAmount, err := captchaRepo.GetActionType(context.TODO(), ip, actionType)
diff --git a/internal/service/action/captcha_service.go b/internal/service/action/captcha_service.go
index edc81667..2b376a22 100644
--- a/internal/service/action/captcha_service.go
+++ b/internal/service/action/captcha_service.go
@@ -18,7 +18,7 @@ type CaptchaRepo interface {
SetCaptcha(ctx context.Context, key, captcha string) (err error)
GetCaptcha(ctx context.Context, key string) (captcha string, err error)
DelCaptcha(ctx context.Context, key string) (err error)
- SetActionType(ctx context.Context, unit, actionType string, amount int) (err error)
+ SetActionType(ctx context.Context, unit, actionType, config string, amount int) (err error)
GetActionType(ctx context.Context, unit, actionType string) (actioninfo *entity.ActionRecordInfo, err error)
DelActionType(ctx context.Context, unit, actionType string) (err error)
}
@@ -69,9 +69,9 @@ func (cs *CaptchaService) UserRegisterVerifyCaptcha(
// ActionRecordVerifyCaptcha
// Verify that you need to enter a CAPTCHA, and that the CAPTCHA is correct
func (cs *CaptchaService) ActionRecordVerifyCaptcha(
- ctx context.Context, actionType string, ip string, id string, VerifyValue string,
+ ctx context.Context, actionType string, unit string, id string, VerifyValue string,
) bool {
- verificationResult := cs.ValidationStrategy(ctx, ip, actionType)
+ verificationResult := cs.ValidationStrategy(ctx, unit, actionType)
if !verificationResult {
if id == "" || VerifyValue == "" {
return false
@@ -85,22 +85,22 @@ func (cs *CaptchaService) ActionRecordVerifyCaptcha(
return true
}
-func (cs *CaptchaService) ActionRecordAdd(ctx context.Context, actionType string, ip string) (int, error) {
+func (cs *CaptchaService) ActionRecordAdd(ctx context.Context, actionType string, unit string) (int, error) {
var err error
- info, cahceErr := cs.captchaRepo.GetActionType(ctx, ip, actionType)
+ info, cahceErr := cs.captchaRepo.GetActionType(ctx, unit, actionType)
if cahceErr != nil {
log.Error(err)
}
info.Num++
- err = cs.captchaRepo.SetActionType(ctx, ip, actionType, info.Num)
+ err = cs.captchaRepo.SetActionType(ctx, unit, actionType, "", info.Num)
if err != nil {
return 0, err
}
return info.Num, nil
}
-func (cs *CaptchaService) ActionRecordDel(ctx context.Context, actionType string, ip string) {
- err := cs.captchaRepo.DelActionType(ctx, ip, actionType)
+func (cs *CaptchaService) ActionRecordDel(ctx context.Context, actionType string, unit string) {
+ err := cs.captchaRepo.DelActionType(ctx, unit, actionType)
if err != nil {
log.Error(err)
}
diff --git a/internal/service/action/captcha_strategy.go b/internal/service/action/captcha_strategy.go
index 27cb9f21..402c6c8b 100644
--- a/internal/service/action/captcha_strategy.go
+++ b/internal/service/action/captcha_strategy.go
@@ -52,70 +52,82 @@ func (cs *CaptchaService) CaptchaActionEmail(ctx context.Context, actioninfo *en
// setNum := 0
// setTime := 0 //seconds
// You need a verification code every time
+ spew.Dump("[CaptchaActionEmail]", actioninfo)
return false
}
func (cs *CaptchaService) CaptchaActionPassword(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionPassword]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionEditUserinfo(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionEditUserinfo]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionQuestion(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionQuestion]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionAnswer(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionAnswer]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionComment(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionComment]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionEdit(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionEdit]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionInvitationAnswer(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionInvitationAnswer]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionSearch(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionSearch]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionReport(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionReport]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionDelete(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionDelete]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false
}
func (cs *CaptchaService) CaptchaActionVote(ctx context.Context, actioninfo *entity.ActionRecordInfo) bool {
+ spew.Dump("[CaptchaActionVote]", actioninfo)
// setNum := 0
// setTime := 0 //seconds
return false