1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 10:55:40 -04:00

api,frontend: add Akismet spam flagging integration

This commit is contained in:
Adhityaa Chandrasekar
2018-12-19 22:57:02 -05:00
parent d1318daaca
commit 9fcf67d667
8 changed files with 102 additions and 19 deletions

31
api/akismet.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"github.com/adtac/go-akismet/akismet"
"os"
)
func isSpam(domain string, userIp string, userAgent string, name string, email string, url string, markdown string) bool {
akismetKey := os.Getenv("AKISMET_KEY")
if akismetKey == "" {
return false
}
res, err := akismet.Check(&akismet.Comment{
Blog: domain,
UserIP: userIp,
UserAgent: userAgent,
CommentType: "comment",
CommentAuthor: name,
CommentAuthorEmail: email,
CommentAuthorURL: url,
CommentContent: markdown,
}, akismetKey)
if err != nil {
logger.Errorf("error: cannot validate commenet using Akismet: %v", err)
return true
}
return res
}