added spam filter
This commit is contained in:
@@ -120,13 +120,17 @@ func CreateComment(c *gin.Context) {
|
|||||||
c.Request.Form.Get("content"),
|
c.Request.Form.Get("content"),
|
||||||
c.Request.Form.Get("url"),
|
c.Request.Form.Get("url"),
|
||||||
c.Request.Form.Get("captcha")}
|
c.Request.Form.Get("captcha")}
|
||||||
|
if len(a[1]) > 180 && len(*GetCommentsByContent(a[1], a[2])) > 0 {
|
||||||
|
c.HTML(http.StatusNotAcceptable, "comment_post_failed.tmpl", CommentDto{Url: a[2]})
|
||||||
|
return
|
||||||
|
}
|
||||||
i, err := strconv.ParseInt(a[3], 10, 32)
|
i, err := strconv.ParseInt(a[3], 10, 32)
|
||||||
if err != nil || int(i) != (captchaVals[0]+captchaVals[1]) {
|
if err != nil || int(i) != (captchaVals[0]+captchaVals[1]) {
|
||||||
c.HTML(http.StatusNotAcceptable, "comment_post_failed.tmpl", CommentDto{Url: a[2]})
|
c.HTML(http.StatusNotAcceptable, "comment_post_failed.tmpl", CommentDto{Url: a[2]})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if GetNumberOfRecentPosts(c) > 3 {
|
if GetNumberOfRecentPosts(c) > 3 {
|
||||||
c.HTML(http.StatusOK, "comment_post_spam.tmpl", CommentDto{Url: a[2]})
|
c.HTML(http.StatusNotAcceptable, "comment_post_spam.tmpl", CommentDto{Url: a[2]})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, v := range a {
|
for _, v := range a {
|
||||||
@@ -163,15 +167,24 @@ func GetAllBlogPosts() *[]models.BlogPost {
|
|||||||
|
|
||||||
func GetBlogPostById(id string) *models.BlogPost {
|
func GetBlogPostById(id string) *models.BlogPost {
|
||||||
var post models.BlogPost
|
var post models.BlogPost
|
||||||
err := db.Where(&models.BlogPost{Url: id}).Find(&post).Error
|
err := db.Model(&post).Where(&models.BlogPost{Url: id}).Find(&post).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: Figure out gorm joins!
|
// TODO: Figure out gorm joins!
|
||||||
// gorm joins are not working at all, just going to do another query to make it work for now.
|
// gorm joins are not working at all, just going to do another query to make it work for now.
|
||||||
err = db.Where(&models.Comment{AssociatedPost: id}).Find(&post.Comments).Error
|
err = db.Model(&models.Comment{}).Where(&models.Comment{AssociatedPost: id}).Find(&post.Comments).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &post
|
return &post
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetCommentsByContent(content string, url string) *[]models.Comment {
|
||||||
|
var comments []models.Comment
|
||||||
|
err := db.Model(&comments).Where("content like ? and associated_post like ?", "%"+content+"%", url).Scan(&comments).Error
|
||||||
|
if err != nil {
|
||||||
|
return &[]models.Comment{}
|
||||||
|
}
|
||||||
|
return &comments
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<li>You failed the captcha.</li>
|
<li>You failed the captcha.</li>
|
||||||
<li>Your post had links in it.</li>
|
<li>Your post had links in it.</li>
|
||||||
<li>The name on your comment was "rawley" or "admin".</li>
|
<li>The name on your comment was "rawley" or "admin".</li>
|
||||||
|
<li>You're spamming!</li>
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
6
utils/spam_checker.go
Normal file
6
utils/spam_checker.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
// TODO: Implement a spam checking module
|
||||||
|
func IsSpam(t string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user