Skip to content

Commit

Permalink
fest: 支持评论免审核设置 #58
Browse files Browse the repository at this point in the history
  • Loading branch information
fesiong committed Aug 4, 2024
1 parent c1f9396 commit bbb333a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
24 changes: 22 additions & 2 deletions controller/apiTag.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,20 @@ func ApiCommentPublish(ctx iris.Context) {
req.ToUid = parent.UserId
}
}
// 是否需要审核
var contentVerify = true
userGroup := ctx.Values().Get("userGroup")
if userGroup != nil {
group, ok := userGroup.(*model.UserGroup)
if ok {
contentVerify = !group.Setting.ContentNoVerify
}
}
req.Status = 0
if contentVerify == false {
// 不需要审核
req.Status = 1
}

comment, err := currentSite.SaveComment(&req)
if err != nil {
Expand Down Expand Up @@ -1451,8 +1465,14 @@ func ApiArchivePublish(ctx iris.Context) {
})
return
}
if currentSite.Safe.APIPublish != 1 {
req.Draft = true
// 是否需要审核
req.Draft = currentSite.Safe.APIPublish != 1
userGroup := ctx.Values().Get("userGroup")
if userGroup != nil {
group, ok := userGroup.(*model.UserGroup)
if ok {
req.Draft = !group.Setting.ContentNoVerify
}
}
userId := ctx.Values().GetIntDefault("userId", 0)
req.UserId = uint(userId)
Expand Down
20 changes: 18 additions & 2 deletions controller/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/kataras/iris/v12"
"kandaoni.com/anqicms/config"
"kandaoni.com/anqicms/model"
"kandaoni.com/anqicms/provider"
"kandaoni.com/anqicms/request"
"kandaoni.com/anqicms/response"
Expand All @@ -27,9 +28,24 @@ func CommentPublish(ctx iris.Context) {

//登录状态的用户,发布不进审核,否则进审核
status := uint(0)
userId := ctx.Values().GetIntDefault("adminId", 0)
if userId > 0 {
userId := ctx.Values().GetIntDefault("userId", 0)
adminId := ctx.Values().GetIntDefault("adminId", 0)
if adminId > 0 {
status = 1
} else {
// 是否需要审核
var contentVerify = true
userGroup := ctx.Values().Get("userGroup")
if userGroup != nil {
group, ok := userGroup.(*model.UserGroup)
if ok {
contentVerify = !group.Setting.ContentNoVerify
}
}
if contentVerify == false {
// 不需要审核
status = 1
}
}

var req request.PluginComment
Expand Down
12 changes: 11 additions & 1 deletion controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,18 @@ func GenerateCaptcha(ctx iris.Context) {

func SafeVerify(ctx iris.Context, req map[string]string, returnType string, from string) bool {
currentSite := provider.CurrentSite(ctx)
// 检查如果用户是否登录
// 是否需要验证码
var contentCaptcha = currentSite.Safe.Captcha == 1
userGroup := ctx.Values().Get("userGroup")
if userGroup != nil {
group, ok := userGroup.(*model.UserGroup)
if ok {
contentCaptcha = !group.Setting.ContentNoCaptcha
}
}
// 检查验证码
if currentSite.Safe.Captcha == 1 {
if contentCaptcha {
captchaId := ctx.PostValueTrim("captcha_id")
captchaValue := ctx.PostValueTrim("captcha")
if req != nil {
Expand Down
3 changes: 3 additions & 0 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type UserGroupSetting struct {
ParentReward int64 `json:"parent_reward"`
Discount int64 `json:"discount"`
ExpireDay int `json:"expire_day"`

ContentNoVerify bool `json:"content_no_verify"` // 评论/内容发布是否不需要审核
ContentNoCaptcha bool `json:"content_no_captcha"` // 评论/内容发布是否不需要验证码
}

// Value implements the driver.Valuer interface.
Expand Down
4 changes: 2 additions & 2 deletions provider/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ func (w *Website) SaveComment(req *request.PluginComment) (comment *model.Commen
}
} else {
comment = &model.Comment{
Status: 0,
Status: req.Status,
ArchiveId: req.ArchiveId,
UserId: req.UserId,
Ip: req.Ip,
ParentId: req.ParentId,
ToUid: req.ToUid,
}
}

comment.Status = req.Status
comment.UserName = req.UserName
comment.Content = req.Content

Expand Down

0 comments on commit bbb333a

Please sign in to comment.