You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
864 B
Python

from functools import wraps
from django.shortcuts import redirect
from osinacore.models import *
from django.http import QueryDict
def customer_login_required(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
# Check if the user is logged in and is a staff member
if not request.user.is_authenticated or not CustomerProfile.objects.filter(user=request.user):
# Capture the 'next' page
next_page = request.build_absolute_uri()
query_params = QueryDict(mutable=True)
query_params['next'] = next_page
query_string = query_params.urlencode()
login_url = f"/login/?{query_string}" # Change the login URL as per your project setup
return redirect(login_url)
return view_func(request, *args, **kwargs)
return _wrapped_view