Template
Add shopper accounts, reviews, tracking, and seed_demo (#9)
Closes #9. Shop-gated buyer accounts, purchase reviews, Stripe customer ids, shipment tracking, slim public contact form, and a template-neutral seed_demo command.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from django.shortcuts import redirect
|
||||
|
||||
|
||||
class PortalStaffMiddleware:
|
||||
"""Keep customer accounts out of the staff portal. Webhooks stay public."""
|
||||
|
||||
PORTAL_PREFIX = "/portal/"
|
||||
WEBHOOK_INFIX = "/webhooks/"
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
path = request.path
|
||||
if path.startswith(self.PORTAL_PREFIX) and self.WEBHOOK_INFIX not in path:
|
||||
user = getattr(request, "user", None)
|
||||
if (
|
||||
user is not None
|
||||
and getattr(user, "is_authenticated", False)
|
||||
and not getattr(user, "is_staff", False)
|
||||
):
|
||||
from django.apps import apps
|
||||
|
||||
if apps.is_installed("shop"):
|
||||
return redirect("account:home")
|
||||
return redirect("public:home")
|
||||
return self.get_response(request)
|
||||
Reference in New Issue
Block a user