From 0004e2e68278b54cc50f976a7ebf2d1494bbe12e Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Sat, 7 Sep 2024 12:37:47 +0330 Subject: [PATCH 1/6] fixed zora syntax error --- core/constraints/zora.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/constraints/zora.py b/core/constraints/zora.py index bed49bd..6d791d0 100644 --- a/core/constraints/zora.py +++ b/core/constraints/zora.py @@ -12,8 +12,8 @@ class DidMintZoraNFT(ConstraintVerification): app_name = ConstraintApp.ZORA.value _param_keys = [ConstraintParam.ADDRESS] - def __init__(self, user_profile) -> None: - super().__init__(user_profile) + def __init__(self, user_profile, *, obj=None) -> None: + super().__init__(user_profile, obj=obj) def is_observed(self, *args, **kwargs) -> bool: zora_util = ZoraUtil() From 2b375da7d003e6f8e2102759a50dcf7384dcbc69 Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Sat, 7 Sep 2024 12:38:34 +0330 Subject: [PATCH 2/6] modified turnsite token key for hcaptcha --- core/constraints/captcha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/constraints/captcha.py b/core/constraints/captcha.py index 070ef11..6b83d38 100644 --- a/core/constraints/captcha.py +++ b/core/constraints/captcha.py @@ -60,7 +60,7 @@ def is_observed(self, *args, **kwargs) -> bool: context["request"] ) - turnstile_token = request_context.data.get("cf-turnstile-response") + turnstile_token = request_context.data.get("hc-turnstile-response") or request_context.data.get("cf-turnstile-response") return request_context.ip is not None and turnstile_token is not None and hcaptcha.is_verified( turnstile_token, request_context.ip From 1c3f4fdc65f9101e5fe730708b8230745f29be47 Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Sat, 7 Sep 2024 13:05:10 +0330 Subject: [PATCH 3/6] modified reading tokens from headers --- brightIDfaucet/settings.py | 7 +++++++ core/constraints/captcha.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/brightIDfaucet/settings.py b/brightIDfaucet/settings.py index 79dbf66..bbedd01 100644 --- a/brightIDfaucet/settings.py +++ b/brightIDfaucet/settings.py @@ -7,6 +7,8 @@ from dotenv import load_dotenv from sentry_sdk.integrations.django import DjangoIntegration +from corsheaders.defaults import default_headers + from faucet.faucet_manager.bright_id_interface import BrightIDInterface load_dotenv() @@ -244,6 +246,11 @@ def before_send(event, hint): else: CORS_ALLOW_ALL_ORIGINS = True +CORS_ALLOW_HEADERS = list(default_headers) + [ + 'cf-turnstile-response', + 'hc-turnstile-response', +] + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ diff --git a/core/constraints/captcha.py b/core/constraints/captcha.py index 6b83d38..7c29e3a 100644 --- a/core/constraints/captcha.py +++ b/core/constraints/captcha.py @@ -31,7 +31,7 @@ def is_observed(self, *args, **kwargs) -> bool: context["request"] ) - turnstile_token = request_context.data.get("cf-turnstile-response") + turnstile_token = request_context.headers.get("cf-turnstile-response") return request_context.ip is not None and turnstile_token is not None and cloudflare.is_verified( turnstile_token, request_context.ip @@ -60,7 +60,7 @@ def is_observed(self, *args, **kwargs) -> bool: context["request"] ) - turnstile_token = request_context.data.get("hc-turnstile-response") or request_context.data.get("cf-turnstile-response") + turnstile_token = request_context.headers.get("hc-turnstile-response") return request_context.ip is not None and turnstile_token is not None and hcaptcha.is_verified( turnstile_token, request_context.ip From 67b63e6409d034a202252178bf342d3457631b6a Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Sat, 7 Sep 2024 13:09:37 +0330 Subject: [PATCH 4/6] added comments for more readability --- brightIDfaucet/settings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightIDfaucet/settings.py b/brightIDfaucet/settings.py index bbedd01..bafc6cb 100644 --- a/brightIDfaucet/settings.py +++ b/brightIDfaucet/settings.py @@ -246,6 +246,10 @@ def before_send(event, hint): else: CORS_ALLOW_ALL_ORIGINS = True + +# Add Turnstile response headers for CORS +# These headers are required for Cloudflare and HCaptcha Turnstile anti-bot service + CORS_ALLOW_HEADERS = list(default_headers) + [ 'cf-turnstile-response', 'hc-turnstile-response', From 3e7f12488b38886e386da198a79d92f306ded6ad Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Fri, 13 Sep 2024 12:20:03 +0330 Subject: [PATCH 5/6] fixed record urls --- .../migrations/0079_fix_raffle_image_urls.py | 32 +++++++++++++++ .../migrations/0065_fix_token_image_prefix.py | 40 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 prizetap/migrations/0079_fix_raffle_image_urls.py create mode 100644 tokenTap/migrations/0065_fix_token_image_prefix.py diff --git a/prizetap/migrations/0079_fix_raffle_image_urls.py b/prizetap/migrations/0079_fix_raffle_image_urls.py new file mode 100644 index 0000000..7574063 --- /dev/null +++ b/prizetap/migrations/0079_fix_raffle_image_urls.py @@ -0,0 +1,32 @@ +# Generated by Django 4.0.4 on 2024-08-25 09:12 + +from django.db import migrations, models + + +def fix_raffle_images_prefix(apps, schema): + Raffle = apps.get_model("prizetap", "Raffle") + + raffles = Raffle.objects.all() + + for raffle in raffles: + if ( + raffle.image + and raffle.image.name + and raffle.image.name.startswith("https://imagedelivery.net") + ): + # split the url to get the image id + raffle.image.name = raffle.image.name.split("/")[-2] + raffle.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("tokenTap", "0078_alter_constraint_name"), + ] + + operations = [ + migrations.RunPython( + fix_raffle_images_prefix, reverse_code=migrations.RunPython.noop + ) + ] diff --git a/tokenTap/migrations/0065_fix_token_image_prefix.py b/tokenTap/migrations/0065_fix_token_image_prefix.py new file mode 100644 index 0000000..d1df6a4 --- /dev/null +++ b/tokenTap/migrations/0065_fix_token_image_prefix.py @@ -0,0 +1,40 @@ +# Generated by Django 4.0.4 on 2024-08-25 09:12 + +from django.db import migrations, models + + +def fix_token_images_prefix(apps, schema_editor): + TokenDistribution = apps.get_model("tokenTap", "TokenDistribution") + + tokens = TokenDistribution.objects.all() + + for token in tokens: + if ( + token.image + and token.image.name + and token.image.name.startswith("https://imagedelivery.net") + ): + # split the url to get the image id + token.image.name = token.image.name.split("/")[-2] + token.save() + + if ( + token.token_image + and token.token_image.name + and token.token_image.name.startswith("https://imagedelivery.net") + ): + token.token_image.name = token.token_image.name.split("/")[-2] + token.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("tokenTap", "0064_alter_constraint_name"), + ] + + operations = [ + migrations.RunPython( + fix_token_images_prefix, reverse_code=migrations.RunPython.noop + ) + ] From a1914237c69ee61d744452ac89fa57fee404c270 Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Fri, 13 Sep 2024 12:23:46 +0330 Subject: [PATCH 6/6] fixed parent node migration issue --- prizetap/migrations/0079_fix_raffle_image_urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prizetap/migrations/0079_fix_raffle_image_urls.py b/prizetap/migrations/0079_fix_raffle_image_urls.py index 7574063..cf85d93 100644 --- a/prizetap/migrations/0079_fix_raffle_image_urls.py +++ b/prizetap/migrations/0079_fix_raffle_image_urls.py @@ -22,7 +22,7 @@ def fix_raffle_images_prefix(apps, schema): class Migration(migrations.Migration): dependencies = [ - ("tokenTap", "0078_alter_constraint_name"), + ("prizetap", "0078_alter_constraint_name"), ] operations = [