diff --git a/core/constraints/abstract.py b/core/constraints/abstract.py index e0f70f9..5292c94 100644 --- a/core/constraints/abstract.py +++ b/core/constraints/abstract.py @@ -56,10 +56,9 @@ class ConstraintVerification(ABC): app_name = ConstraintApp.GENERAL.value __response_text = "" - def __init__(self, user_profile, context=None) -> None: + def __init__(self, user_profile) -> None: self.user_profile = user_profile self._param_values = {} - self.context = context def get_info(self, *args, **kwargs): pass diff --git a/core/constraints/captcha.py b/core/constraints/captcha.py index feac1eb..458ce4c 100644 --- a/core/constraints/captcha.py +++ b/core/constraints/captcha.py @@ -16,17 +16,19 @@ class HasVerifiedCloudflareCaptcha(ConstraintVerification): def is_observed(self, *args, **kwargs) -> bool: - if self.context is None or self.context.get("requset") is None: + context = kwargs.get("context") + + if context is None or context.get("request") is None: return False cloudflare = CloudflareUtil() request_context: RequestContextExtractor = RequestContextExtractor( - self.context["requset"] + context["request"] ) turnstile_token = request_context.data.get("cf-turnstile-response") - return turnstile_token is not None and cloudflare.is_verified( + return request_context.ip is not None and turnstile_token is not None and cloudflare.is_verified( turnstile_token, request_context.ip ) diff --git a/prizetap/validators.py b/prizetap/validators.py index 3d8e37f..e0ac8f9 100644 --- a/prizetap/validators.py +++ b/prizetap/validators.py @@ -15,7 +15,7 @@ def __init__(self, *args, **kwargs): self.user_profile: UserProfile = kwargs["user_profile"] self.raffle: Raffle = kwargs["raffle"] self.raffle_data: dict = kwargs.get("raffle_data", dict()) - self.request = kwargs.get("requset") + self.request = kwargs.get("request") def can_enroll_in_raffle(self): if not self.raffle.is_claimable: @@ -30,7 +30,7 @@ def check_user_constraints(self, raise_exception=True): result = dict() for c in self.raffle.constraints.all(): constraint: ConstraintVerification = get_constraint(c.name)( - self.user_profile, context={"request": self.request} + self.user_profile ) constraint.response = c.response try: @@ -56,7 +56,7 @@ def check_user_constraints(self, raise_exception=True): ) else: is_verified = constraint.is_observed( - **cdata, from_time=int(self.raffle.start_at.timestamp()) + **cdata, from_time=int(self.raffle.start_at.timestamp()), context={"request": self.request} ) caching_time = 60 * 60 if is_verified else 60 expiration_time = time.time() + caching_time diff --git a/tokenTap/validators.py b/tokenTap/validators.py index 315e464..3ee9ae3 100644 --- a/tokenTap/validators.py +++ b/tokenTap/validators.py @@ -61,7 +61,6 @@ def check_user_permissions(self, raise_exception=True): for c in self.td.constraints.all(): constraint: ConstraintVerification = get_constraint(c.name)( self.user_profile, - context={"request": self.request} ) constraint.response = c.response try: @@ -85,6 +84,7 @@ def check_user_permissions(self, raise_exception=True): is_verified = constraint.is_observed( **cdata, token_distribution=self.td, + context={"request": self.request} ) caching_time = 60 * 60 if is_verified else 60 expiration_time = time.time() + caching_time