Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Rasta_Web/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,6 @@ def get_environment_var(var_name, default, prefixed=True):
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Tehran'
# hCaptcha Configuration
HCAPTCHA_SECRET = 'ES_2e3d6c59b25545518d66440a54b509c8'
HCAPTCHA_SITE_KEY = '2eb27272-fab4-4bee-8b54-2ec48ac0d214'
24 changes: 23 additions & 1 deletion Rasta_Web/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.core.exceptions import ValidationError

from django.conf import settings
from Rasta_Web.settings import base
import requests
from django.contrib import messages
Expand Down Expand Up @@ -29,6 +29,28 @@ def check_bibot_response(request):
messages.error(request, 'ارتباط با سرور بی‌بات برقرار نشده است! آیا جاوااسکریپت شما فعال است؟')
return False

def check_hcaptcha_response(request):
hcaptcha_response = request.POST.get('h-captcha-response')
if hcaptcha_response:
verification_url = "https://hcaptcha.com/siteverify"
payload = {
'secret': settings.HCAPTCHA_SECRET,
'response': hcaptcha_response,
'remoteip': request.META.get('REMOTE_ADDR') # Optional
}
response = requests.post(verification_url, data=payload)
result = response.json()

if result.get('success'):
messages.success(request, 'تأیید hCaptcha با موفقیت انجام شد!')
return True
else:
messages.error(request, 'تأیید hCaptcha ناموفق بود. لطفاً دوباره تلاش کنید.')
return False
else:
messages.error(request, 'لطفاً hCaptcha را تکمیل کنید.')
return False


def validate_image_size(image):
limit_mb = 5
Expand Down
6 changes: 3 additions & 3 deletions apps/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.shortcuts import render

from Rasta_Web.settings.base import bibot_SiteKey
from Rasta_Web.utils import check_bibot_response
from Rasta_Web.utils import check_hcaptcha_response
from apps.blog.forms import CommentForm, ReplyForm
from apps.blog.models import *
from django.template.loader import render_to_string
Expand Down Expand Up @@ -135,8 +135,8 @@ def get_single_post(request, post_id, rest):

def submit_comment_reply(request):
response = {}
if not check_bibot_response(request):
response['bibot_err'] = 'error'
if not check_hcaptcha_response(request):
response['hcaptcha_err'] = 'error'
return HttpResponse(
json.dumps(response),
content_type="application/json"
Expand Down
6 changes: 3 additions & 3 deletions apps/contact_us/templates/contact_us/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ <h2 class="ui dividing center aligned header" style="color: var(--header)">تم
</ul>
{% endif %}

<div class="h-captcha" data-sitekey="2eb27272-fab4-4bee-8b54-2ec48ac0d214"></div>

<button type="submit" class="ui button"
style="background-color: var(--secondary-dark) ;color: white;font-weight: bolder;margin-top: 20px">
ثبت کن !
</button>

</form>
<script src="https://bibot.ir/bibot.min.js"></script>

<script src="https://js.hcaptcha.com/1/api.js" async defer></script>

</div>
<div class="center aligned column" id="contact_element">
Expand All @@ -56,4 +56,4 @@ <h2 class="ui dividing center aligned header" style="color: var(--header)">تم


</div>
</div>
</div>