diff options
| author | Bobby <[email protected]> | 2024-06-06 15:42:07 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-06-06 15:42:07 +0000 |
| commit | a1b32703dc708de3fbfa183353cbea62a0cf6531 (patch) | |
| tree | 310b20ac9314b783bcaa44013888f32417b32092 /blog | |
| parent | a503e64bcd31eb6ae1b105ed5a5a9615d5587f01 (diff) | |
| download | thatcomputerscientist-a1b32703dc708de3fbfa183353cbea62a0cf6531.tar.xz thatcomputerscientist-a1b32703dc708de3fbfa183353cbea62a0cf6531.zip | |
Test Spam
Diffstat (limited to 'blog')
| -rw-r--r-- | blog/context_processors.py | 7 | ||||
| -rw-r--r-- | blog/views.py | 26 |
2 files changed, 8 insertions, 25 deletions
diff --git a/blog/context_processors.py b/blog/context_processors.py index 6f958f9c..99655dc2 100644 --- a/blog/context_processors.py +++ b/blog/context_processors.py @@ -28,7 +28,7 @@ akismet_api = akismet.Akismet( ) -def check_spam(user_ip, user_agent, comment, author): +def check_spam(comment): # spam = False # akismet_data = { # "comment_type": "comment", @@ -55,10 +55,7 @@ def check_spam(user_ip, user_agent, comment, author): r_text = response.text - if r_text == "Y": - return True - else: - return False + return r_text def add_excerpt(post): diff --git a/blog/views.py b/blog/views.py index 8dc8fe60..a05dc325 100644 --- a/blog/views.py +++ b/blog/views.py @@ -224,16 +224,9 @@ def comment(request, slug): if request.method == 'POST': if request.user.is_authenticated: try: - # check for spam first - user_ip = request.META.get('HTTP_X_FORWARDED_FOR') - if user_ip: - user_ip = user_ip.split(',')[0] - else: - user_ip = request.META.get('REMOTE_ADDR') - user_agent_string = request.META.get('HTTP_USER_AGENT', '') - user_agent = parse(user_agent_string) - if check_spam(user_ip=user_ip, user_agent=user_agent, comment=request.POST.get('body'), author=request.user.username): - messages.error(request, request.POST.get('body'), extra_tags='spam') + r_spam = check_spam(comment=request.POST.get('body')) + if r_spam != 'N': + messages.error(request, r_spam, extra_tags='spam') return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#comment-' + str(comment.id)) # then we continue @@ -266,16 +259,9 @@ def anon_comment(request, slug): anonymous_token, at = request.POST.get('anonymous-token'), request.POST.get('anonymous-token') new_anonymous_token = request.POST.get('new-anonymous-token') anonymous_comment = request.POST.get('anonymous-comment') - # check for spam first - user_ip = request.META.get('HTTP_X_FORWARDED_FOR') - if user_ip: - user_ip = user_ip.split(',')[0] - else: - user_ip = request.META.get('REMOTE_ADDR') - user_agent_string = request.META.get('HTTP_USER_AGENT', '') - user_agent = parse(user_agent_string) - if check_spam(user_ip=user_ip, user_agent=user_agent, comment=anonymous_comment, author=anonymous_name): - messages.error(request, anonymous_comment, extra_tags='spam') + res_spam = check_spam(comment=anonymous_comment) + if res_spam != 'N': + messages.error(request, res_spam, extra_tags='spam') return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#new-comment') # now continue with the comment |
