-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #605 from UnitapApp/feature/requirements/captcha
added captcha requirement
- Loading branch information
Showing
16 changed files
with
234 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from core.constraints.abstract import ConstraintApp, ConstraintVerification | ||
from core.thirdpartyapp.cloudflare import CloudflareUtil | ||
|
||
|
||
import logging | ||
|
||
from core.utils import RequestContextExtractor | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class HasVerifiedCloudflareCaptcha(ConstraintVerification): | ||
_param_keys = [] | ||
app_name = ConstraintApp.GENERAL.value | ||
|
||
def is_observed(self, *args, **kwargs) -> bool: | ||
|
||
if self.context is None or self.context.get("requset") is None: | ||
return False | ||
|
||
cloudflare = CloudflareUtil() | ||
|
||
request_context: RequestContextExtractor = RequestContextExtractor( | ||
self.context["requset"] | ||
) | ||
|
||
turnstile_token = request_context.data.get("cf-turnstile-response") | ||
|
||
return turnstile_token is not None and cloudflare.is_verified( | ||
turnstile_token, request_context.ip | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import logging | ||
from django.conf import settings | ||
import requests | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CloudflareUtil: | ||
secret_key = settings.CLOUDFLARE_TURNSTILE_SECRET_KEY | ||
api_url = "https://challenges.cloudflare.com/turnstile/v0" | ||
|
||
def is_verified(self, token: str, ip: str) -> bool: | ||
try: | ||
res = requests.post( | ||
f"{self.api_url}/siteverify", | ||
data={"secret": self.secret_key, "response": token, "remoteip": ip}, | ||
) | ||
|
||
return res.ok and res.json()["success"] | ||
except Exception as e: | ||
logger.info(f"Error occurred during cloudflare verification {str(e)}") | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Generated by Django 4.0.4 on 2024-08-25 09:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def create_prizetap_constraint(apps, schema_editor): | ||
Constraint = apps.get_model("prizetap", "Constraint") | ||
|
||
Constraint.objects.create( | ||
name="core.HasVerifiedCloudflareCaptcha", | ||
description="HasVerifiedCloudflareCaptcha", | ||
title="Passed Cloudflare Captcha", | ||
type="VER", | ||
) | ||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("prizetap", "0075_alter_constraint_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="constraint", | ||
name="name", | ||
field=models.CharField( | ||
choices=[ | ||
("core.BrightIDMeetVerification", "BrightIDMeetVerification"), | ||
("core.BrightIDAuraVerification", "BrightIDAuraVerification"), | ||
("core.HasNFTVerification", "HasNFTVerification"), | ||
("core.HasTokenVerification", "HasTokenVerification"), | ||
( | ||
"core.HasTokenTransferVerification", | ||
"HasTokenTransferVerification", | ||
), | ||
("core.AllowListVerification", "AllowListVerification"), | ||
("core.HasENSVerification", "HasENSVerification"), | ||
("core.HasLensProfile", "HasLensProfile"), | ||
("core.IsFollowingLensUser", "IsFollowingLensUser"), | ||
("core.BeFollowedByLensUser", "BeFollowedByLensUser"), | ||
("core.DidMirrorOnLensPublication", "DidMirrorOnLensPublication"), | ||
("core.DidCollectLensPublication", "DidCollectLensPublication"), | ||
("core.HasMinimumLensPost", "HasMinimumLensPost"), | ||
("core.HasMinimumLensFollower", "HasMinimumLensFollower"), | ||
("core.BeFollowedByFarcasterUser", "BeFollowedByFarcasterUser"), | ||
("core.HasMinimumFarcasterFollower", "HasMinimumFarcasterFollower"), | ||
("core.DidLikedFarcasterCast", "DidLikedFarcasterCast"), | ||
("core.DidRecastFarcasterCast", "DidRecastFarcasterCast"), | ||
("core.IsFollowingFarcasterUser", "IsFollowingFarcasterUser"), | ||
("core.HasFarcasterProfile", "HasFarcasterProfile"), | ||
("core.BeAttestedBy", "BeAttestedBy"), | ||
("core.Attest", "Attest"), | ||
("core.HasDonatedOnGitcoin", "HasDonatedOnGitcoin"), | ||
("core.HasMinimumHumanityScore", "HasMinimumHumanityScore"), | ||
("core.HasGitcoinPassportProfile", "HasGitcoinPassportProfile"), | ||
("core.IsFollowingFarcasterChannel", "IsFollowingFarcasterChannel"), | ||
("core.BridgeEthToArb", "BridgeEthToArb"), | ||
("core.IsFollowinTwitterUser", "IsFollowinTwitterUser"), | ||
("core.BeFollowedByTwitterUser", "BeFollowedByTwitterUser"), | ||
("core.DidRetweetTweet", "DidRetweetTweet"), | ||
("core.DidQuoteTweet", "DidQuoteTweet"), | ||
("core.HasMuonNode", "HasMuonNode"), | ||
("core.DelegateArb", "DelegateArb"), | ||
("core.DelegateOP", "DelegateOP"), | ||
("core.DidDelegateArbToAddress", "DidDelegateArbToAddress"), | ||
("core.DidDelegateOPToAddress", "DidDelegateOPToAddress"), | ||
("core.GLMStakingVerification", "GLMStakingVerification"), | ||
("core.IsFollowingTwitterBatch", "IsFollowingTwitterBatch"), | ||
("core.IsFollowingFarcasterBatch", "IsFollowingFarcasterBatch"), | ||
( | ||
"core.HasVerifiedCloudflareCaptcha", | ||
"HasVerifiedCloudflareCaptcha", | ||
), | ||
("prizetap.HaveUnitapPass", "HaveUnitapPass"), | ||
("prizetap.NotHaveUnitapPass", "NotHaveUnitapPass"), | ||
("faucet.OptimismDonationConstraint", "OptimismDonationConstraint"), | ||
( | ||
"faucet.OptimismClaimingGasConstraint", | ||
"OptimismClaimingGasConstraint", | ||
), | ||
], | ||
max_length=255, | ||
unique=True, | ||
), | ||
), | ||
migrations.RunPython(create_prizetap_constraint), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
python manage.py collectstatic --noinput | ||
python manage.py migrate | ||
python manage.py runserver 0.0.0.0:5678 & | ||
python manage.py runserver 0.0.0.0:5678 | ||
celery -A brightIDfaucet worker -B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.0.4 on 2024-08-25 09:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
|
||
def create_tokentap_constraint(apps, schema_editor): | ||
Constraint = apps.get_model("tokenTap", "Constraint") | ||
|
||
Constraint.objects.create( | ||
name="core.HasVerifiedCloudflareCaptcha", | ||
description="HasVerifiedCloudflareCaptcha", | ||
title="Passed Cloudflare Captcha", | ||
type="VER", | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('tokenTap', '0061_alter_constraint_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='constraint', | ||
name='name', | ||
field=models.CharField(choices=[('core.BrightIDMeetVerification', 'BrightIDMeetVerification'), ('core.BrightIDAuraVerification', 'BrightIDAuraVerification'), ('core.HasNFTVerification', 'HasNFTVerification'), ('core.HasTokenVerification', 'HasTokenVerification'), ('core.HasTokenTransferVerification', 'HasTokenTransferVerification'), ('core.AllowListVerification', 'AllowListVerification'), ('core.HasENSVerification', 'HasENSVerification'), ('core.HasLensProfile', 'HasLensProfile'), ('core.IsFollowingLensUser', 'IsFollowingLensUser'), ('core.BeFollowedByLensUser', 'BeFollowedByLensUser'), ('core.DidMirrorOnLensPublication', 'DidMirrorOnLensPublication'), ('core.DidCollectLensPublication', 'DidCollectLensPublication'), ('core.HasMinimumLensPost', 'HasMinimumLensPost'), ('core.HasMinimumLensFollower', 'HasMinimumLensFollower'), ('core.BeFollowedByFarcasterUser', 'BeFollowedByFarcasterUser'), ('core.HasMinimumFarcasterFollower', 'HasMinimumFarcasterFollower'), ('core.DidLikedFarcasterCast', 'DidLikedFarcasterCast'), ('core.DidRecastFarcasterCast', 'DidRecastFarcasterCast'), ('core.IsFollowingFarcasterUser', 'IsFollowingFarcasterUser'), ('core.HasFarcasterProfile', 'HasFarcasterProfile'), ('core.BeAttestedBy', 'BeAttestedBy'), ('core.Attest', 'Attest'), ('core.HasDonatedOnGitcoin', 'HasDonatedOnGitcoin'), ('core.HasMinimumHumanityScore', 'HasMinimumHumanityScore'), ('core.HasGitcoinPassportProfile', 'HasGitcoinPassportProfile'), ('core.IsFollowingFarcasterChannel', 'IsFollowingFarcasterChannel'), ('core.BridgeEthToArb', 'BridgeEthToArb'), ('core.IsFollowinTwitterUser', 'IsFollowinTwitterUser'), ('core.BeFollowedByTwitterUser', 'BeFollowedByTwitterUser'), ('core.DidRetweetTweet', 'DidRetweetTweet'), ('core.DidQuoteTweet', 'DidQuoteTweet'), ('core.HasMuonNode', 'HasMuonNode'), ('core.DelegateArb', 'DelegateArb'), ('core.DelegateOP', 'DelegateOP'), ('core.DidDelegateArbToAddress', 'DidDelegateArbToAddress'), ('core.DidDelegateOPToAddress', 'DidDelegateOPToAddress'), ('core.GLMStakingVerification', 'GLMStakingVerification'), ('core.IsFollowingTwitterBatch', 'IsFollowingTwitterBatch'), ('core.IsFollowingFarcasterBatch', 'IsFollowingFarcasterBatch'), ('core.HasVerifiedCloudflareCaptcha', 'HasVerifiedCloudflareCaptcha'), ('tokenTap.OncePerMonthVerification', 'OncePerMonthVerification'), ('tokenTap.OnceInALifeTimeVerification', 'OnceInALifeTimeVerification'), ('faucet.OptimismHasClaimedGasConstraint', 'OptimismHasClaimedGasConstraint')], max_length=255, unique=True), | ||
), | ||
migrations.RunPython(create_tokentap_constraint), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters