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 | |
| parent | a503e64bcd31eb6ae1b105ed5a5a9615d5587f01 (diff) | |
| download | thatcomputerscientist-a1b32703dc708de3fbfa183353cbea62a0cf6531.tar.xz thatcomputerscientist-a1b32703dc708de3fbfa183353cbea62a0cf6531.zip | |
Test Spam
| -rw-r--r-- | .github/workflows/main.yml | 8 | ||||
| -rw-r--r-- | blog/context_processors.py | 7 | ||||
| -rw-r--r-- | blog/views.py | 26 | ||||
| -rw-r--r-- | templates/blog/post.html | 1 |
4 files changed, 12 insertions, 30 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dcb082eb..30508f4c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,10 +13,8 @@ jobs: key: ${{ secrets.KEY_ED25519 }} port: ${{ secrets.PORT }} script: | - # if [ -z "$GEMINI_API_KEY" ]; then - # export GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }} - # fi - # Add to /home/ubuntu/.shifooenv grep -qxF 'GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}' /home/ubuntu/.shifooenv || echo 'GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}' >> /home/ubuntu/.shifooenv - cat /home/ubuntu/deploy.sh + # Print the environment variables - test purpose + cat /home/ubuntu/.shifooenv + echo "Deploying the code" sh /home/ubuntu/deploy.sh 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 diff --git a/templates/blog/post.html b/templates/blog/post.html index b0b6194b..5c02ce2b 100644 --- a/templates/blog/post.html +++ b/templates/blog/post.html @@ -184,6 +184,7 @@ background: #ffffff0d; {% for message in messages %} {% if 'spam' in message.tags %} <p style="color: red;">Your comment was not allowed as it was marked as possible spam. If you think this is a mistake, please contact me at <a href="mailto:[email protected]">[email protected]</a>.</p> + <p style="color: red;">{{ message }}</p> {% endif %} {% endfor %} {% endif %} |
