added bot punishing feature
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
{{ end }}
|
||||
<h4>Leave a comment!</h4>
|
||||
<form method="POST" action="/blog/post/comment">
|
||||
<input type="text" required pattern=".{3,}" title="Author name must be atleast 3 chars." placeholder="Name" maxlength="50" name="author"/>
|
||||
<input type="field" required pattern=".{15,}" title="Your comment must be atleast 15 chars." placeholder="Comment" maxlength="500" name="content" />
|
||||
<input type="text" required pattern="^\d+" title="The captcha must be a number." placeholder="What is {{ index .Captcha 0 }} + {{ index .Captcha 1 }}?" maxlength="10" name="captcha" />
|
||||
<input type="text" required pattern=".{3,}" title="Author name must be atleast 3 chars" placeholder="Name" maxlength="50" name="author"/>
|
||||
<input type="field" required pattern=".{15,}" title="Your comment must be atleast 15 chars" placeholder="Comment" maxlength="500" name="content" />
|
||||
<input type="text" class="captcha" required pattern="^\d+" title="The captcha must be a number" placeholder="What is {{ index .Captcha 0 }} plus {{ index .Captcha 1 }}" maxlength="10" name="captcha" />
|
||||
<input type="text" required style="display: none;" name="url" value="{{ .Post.Url }}" readonly />
|
||||
<button type="submit">Post</button>
|
||||
</form>
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user