From 4c3501cc977f0b9243f90cf2f801e244fbf9610e Mon Sep 17 00:00:00 2001 From: rawleyIfowler Date: Thu, 3 Mar 2022 21:33:39 -0600 Subject: [PATCH] added bot punishing feature --- controllers/blog.go | 4 ++-- templates/blog_post.tmpl | 6 +++--- utils/captcha.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/controllers/blog.go b/controllers/blog.go index 407bb7f..ef87381 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -52,7 +52,7 @@ func RegisterBlogGroup(r *gin.RouterGroup) { r.POST("/post") r.POST("/post/comment", CreateComment) // Clear the commenters cache every 15 minutes - go utils.TimedClearMap(&recentPosters, 180000*5) + go utils.TimedClearMap(&recentPosters, 320000*5) go utils.UpdateCaptcha(&captchaVals) } @@ -101,7 +101,7 @@ func CreateComment(c *gin.Context) { c.HTML(http.StatusNotAcceptable, "comment_post_failed.tmpl", CommentDto{Url: a[2]}) return } - if GetNumberOfRecentPosts(c) > 3 { + if GetNumberOfRecentPosts(c) >= 2 { c.HTML(http.StatusNotAcceptable, "comment_post_spam.tmpl", CommentDto{Url: a[2]}) return } diff --git a/templates/blog_post.tmpl b/templates/blog_post.tmpl index c8c7b5b..abb3363 100644 --- a/templates/blog_post.tmpl +++ b/templates/blog_post.tmpl @@ -27,9 +27,9 @@ {{ end }}

Leave a comment!

- - - + + +
diff --git a/utils/captcha.go b/utils/captcha.go index babedc5..54eb589 100644 --- a/utils/captcha.go +++ b/utils/captcha.go @@ -12,6 +12,6 @@ func GenerateCaptchaValues() (int, int) { func UpdateCaptcha(captcha *[2]int) { for { captcha[0], captcha[1] = GenerateCaptchaValues() - time.Sleep(5 * time.Minute) + time.Sleep(30 * time.Minute) } }