


from django.shortcuts import redirect
import logging
from django.core.signals import request_started
from django.dispatch import receiver
from social_core.pipeline import social_auth

from social_core import backends

logger = logging.getLogger(__name__)

def loginRedirect(get_response):

    def middleware(request):
        
        try:
            
                
            response = get_response(request)
            if request.path.startswith('/myecolux') and ( not request.user.is_authenticated or (request.user.is_authenticated and not request.user.is_staff)) :
                print(':::::::::: myecolux ::::::::::::::')
                return redirect('/auth/to_login')
            
                
        except Exception as e:
            print(e)
            

        return response

    return middleware




