This commit is contained in:
IGNY8 VPS (Salman)
2025-12-08 07:11:06 +00:00
parent 7483de6aba
commit d144f5d19a
13 changed files with 2209 additions and 842 deletions

View File

@@ -132,27 +132,14 @@ class AccountContextMiddleware(MiddlewareMixin):
def _validate_account_and_plan(self, request, user):
"""
Ensure the authenticated user has an account and an active plan.
If not, logout the user (for session auth) and block the request.
Uses shared validation helper for consistency.
"""
try:
account = getattr(user, 'account', None)
except Exception:
account = None
from .utils import validate_account_and_plan
if not account:
return self._deny_request(
request,
error='Account not configured for this user. Please contact support.',
status_code=status.HTTP_403_FORBIDDEN,
)
is_valid, error_message, http_status = validate_account_and_plan(user)
plan = getattr(account, 'plan', None)
if plan is None or getattr(plan, 'is_active', False) is False:
return self._deny_request(
request,
error='Active subscription required. Visit igny8.com/pricing to subscribe.',
status_code=status.HTTP_402_PAYMENT_REQUIRED,
)
if not is_valid:
return self._deny_request(request, error_message, http_status)
return None