Merge branch 'feat/1.3.1/code' into test
This commit is contained in:
@@ -38,6 +38,9 @@ type AddCommentReq struct {
|
||||
ParsedText string `json:"-"`
|
||||
// @ user id list
|
||||
MentionUsernameList []string `validate:"omitempty" json:"mention_username_list"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
|
||||
// user id
|
||||
UserID string `json:"-"`
|
||||
// whether user can add it
|
||||
@@ -45,9 +48,7 @@ type AddCommentReq struct {
|
||||
// whether user can edit it
|
||||
CanEdit bool `json:"-"`
|
||||
// whether user can delete it
|
||||
CanDelete bool `json:"-"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
CanDelete bool `json:"-"`
|
||||
}
|
||||
|
||||
func (req *AddCommentReq) Check() (errFields []*validator.FormErrorField, err error) {
|
||||
@@ -61,7 +62,7 @@ type RemoveCommentReq struct {
|
||||
CommentID string `validate:"required" json:"comment_id"`
|
||||
// user id
|
||||
UserID string `json:"-"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ import (
|
||||
)
|
||||
|
||||
type SearchDTO struct {
|
||||
UserID string // UserID current login user ID
|
||||
Query string `validate:"required,gte=1,lte=60" json:"q" form:"q"` // Query the query string
|
||||
Page int `validate:"omitempty,min=1" form:"page,default=1" json:"page"` //Query number of pages
|
||||
Size int `validate:"omitempty,min=1,max=50" form:"size,default=30" json:"size"` //Search page size
|
||||
Order string `validate:"required,oneof=newest active score relevance" form:"order,default=relevance" json:"order" enums:"newest,active,score,relevance"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
Query string `validate:"required,gte=1,lte=60" form:"q"`
|
||||
Page int `validate:"omitempty,min=1" form:"page,default=1"`
|
||||
Size int `validate:"omitempty,min=1,max=50" form:"size,default=30"`
|
||||
Order string `validate:"required,oneof=newest active score relevance" form:"order,default=relevance" enums:"newest,active,score,relevance"`
|
||||
CaptchaID string `form:"captcha_id"`
|
||||
CaptchaCode string `form:"captcha_code"`
|
||||
UserID string `json:"-"`
|
||||
}
|
||||
|
||||
func (s *SearchDTO) Check() (errField []*validator.FormErrorField, err error) {
|
||||
|
||||
@@ -220,8 +220,8 @@ func (u *UserRegisterReq) Check() (errFields []*validator.FormErrorField, err er
|
||||
type UserModifyPasswordReq struct {
|
||||
OldPass string `validate:"omitempty,gte=8,lte=32" json:"old_pass"`
|
||||
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
|
||||
CaptchaID string `validate:"omitempty,gt=0,lte=500" json:"captcha_id"`
|
||||
CaptchaCode string `validate:"omitempty,gt=0,lte=500" json:"captcha_code"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
UserID string `json:"-"`
|
||||
AccessToken string `json:"-"`
|
||||
}
|
||||
@@ -382,8 +382,8 @@ type UserChangeEmailVerifyReq struct {
|
||||
}
|
||||
|
||||
type UserVerifyEmailSendReq struct {
|
||||
CaptchaID string `validate:"omitempty,gt=0,lte=500" json:"captcha_id"`
|
||||
CaptchaCode string `validate:"omitempty,gt=0,lte=500" json:"captcha_code"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
// UserRankingResp user ranking response
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
package schema
|
||||
|
||||
type VoteReq struct {
|
||||
ObjectID string `validate:"required" form:"object_id" json:"object_id"` // id
|
||||
IsCancel bool `validate:"omitempty" form:"is_cancel" json:"is_cancel"` // is cancel
|
||||
UserID string `json:"-"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
ObjectID string `validate:"required" json:"object_id"`
|
||||
IsCancel bool `validate:"omitempty" json:"is_cancel"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
UserID string `json:"-"`
|
||||
}
|
||||
|
||||
type VoteResp struct {
|
||||
|
||||
@@ -63,3 +63,20 @@ func CaptchaEnabled() (enabled bool) {
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func coordinatedCaptchaPlugins(slugName string) (enabledSlugNames []string) {
|
||||
isCaptcha := false
|
||||
_ = callCaptcha(func(captcha Captcha) error {
|
||||
name := captcha.Info().SlugName
|
||||
if slugName == name {
|
||||
isCaptcha = true
|
||||
} else {
|
||||
enabledSlugNames = append(enabledSlugNames, name)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if isCaptcha {
|
||||
return enabledSlugNames
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync"
|
||||
|
||||
"github.com/segmentfault/pacman/i18n"
|
||||
|
||||
@@ -142,11 +143,21 @@ func MakePlugin[T Base](super bool) (CallFn[T], RegisterFn[T]) {
|
||||
}
|
||||
|
||||
type statusManager struct {
|
||||
lock sync.Mutex
|
||||
status map[string]bool
|
||||
}
|
||||
|
||||
func (m *statusManager) Enable(name string, enabled bool) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
if !enabled {
|
||||
m.status[name] = enabled
|
||||
return
|
||||
}
|
||||
m.status[name] = enabled
|
||||
for _, slugName := range coordinatedCaptchaPlugins(name) {
|
||||
m.status[slugName] = false
|
||||
}
|
||||
}
|
||||
|
||||
func (m *statusManager) IsEnabled(name string) bool {
|
||||
|
||||
Reference in New Issue
Block a user