from django.shortcuts import HttpResponseRedirect
#from django.core.urlresolvers import reverse
from django.urls import reverse


class AuthRequiredMiddleware(object):
	def __init__(self, get_response):
		self.get_response = get_response

	def __call__(self, request):
		# Code to be executed for each request before
		# the view (and later middleware) are called.

		response = self.get_response(request)
		print (request.path_info)
		print (reverse('login'))

		print(request.path_info)

		if "/catalog/streaming/" in request.path_info:
			return response
			
		if "/catalog/api/" in request.path_info:
			return response
			
		if request.path_info == reverse('ws-news-list2') or request.path_info == reverse('signup') or request.path_info == reverse('status'):
			return response

		if not request.user.is_authenticated and request.path_info != reverse('login'):
			return HttpResponseRedirect(reverse('login'))

		# Code to be executed for each request/response after
		# the view is called.

		return response
