コード例 #1
0
ファイル: signals.py プロジェクト: Spoylerman/libaoyinblog
def validate_comment(sender, comment, request, *args, **kwargs):
    akismet_enable=OptionSet.get('akismet_enable', 0)
    domain="http://%s"%(Site.objects.get_current().domain)
    if int(akismet_enable) == 0:
        return
    
    akismet_key=OptionSet.get('akismet_key', '')
    ak = Akismet(
            #key = 'cda0f27f8e2f',
            key=akismet_key,
            blog_url=domain
        )
    try:
        if ak.verify_key():
            data = {
                'user_ip': request.META.get('REMOTE_ADDR', '127.0.0.1'),
                'user_agent': request.META.get('HTTP_USER_AGENT', ''),
                'referrer': request.META.get('HTTP_REFERER', ''),
                'comment_type': 'comment',
                'comment_author': comment.author.encode('utf-8'),
            }
            if ak.comment_check(comment.content.encode('utf-8'), data=data, build_data=True):
                comment.is_public = False
                comment.save()
                
                ak.submit_spam(comment.content.encode('utf-8'), data=data, build_data=True)
                
    except AkismetError:
        pass
コード例 #2
0
ファイル: tasks.py プロジェクト: chon219/light
def check_comment(comment):
    user_ip = comment.ipaddr
    user_agent = comment.useragent
    comment_author = comment.name
    comment_author_email = comment.email
    comment_author_url = comment.url
    comment_content = comment.content
    data = {
        "user_ip": user_ip,
        "user_agent": user_agent,
        "comment_author": comment_author,
        "comment_author_email": comment_author_email,
        "comment_author_url": comment_author_url,
        "comment_content": comment_content}
    akismet = Akismet(settings.AKISMET_KEY, settings.SITE_URL)
    if akismet.check(data):
        return True
    else:
        from blog.models import EmailBlacklist, IPBlacklist
        emails = EmailBlacklist.objects.filter(email=comment.email)
        ips = IPBlacklist.objects.filter(ipaddr=comment.ipaddr)
        if emails or ips:
            return True
        else:
            return False
コード例 #3
0
ファイル: tasks.py プロジェクト: chon219/light
def submit_spam(comment):
    user_ip = comment.ipaddr
    user_agent = comment.useragent
    comment_author = comment.name
    comment_author_email = comment.email
    comment_author_url = comment.url
    comment_content = comment.content
    data = {
        "user_ip": user_ip,
        "user_agent": user_agent,
        "comment_author": comment_author,
        "comment_author_email": comment_author_email,
        "comment_author_url": comment_author_url,
        "comment_content": comment_content}
    akismet = Akismet(settings.AKISMET_KEY, settings.SITE_URL)
    akismet.submit_spam(data)
    from blog.models import EmailBlacklist, IPBlacklist
    emails = EmailBlacklist.objects.filter(email=comment.email)
    ips = IPBlacklist.objects.filter(ipaddr=comment.ipaddr)
    if not emails:
        EmailBlacklist.objects.create(email=comment.email)
    if not ips:
        IPBlacklist.objects.create(ipaddr=comment.ipaddr)