Skip to content

Commit

Permalink
Added media paths
Browse files Browse the repository at this point in the history
  • Loading branch information
RajatGupta02 committed Apr 15, 2023
1 parent 90defb8 commit 8c3d9ee
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/yearbook/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
USER_MODEL = User

# An array of path regexes that will not be processed by the middleware
PUBLIC_PATHS = ['^/public.*','^/$','^/static.*','^/admin']
PUBLIC_PATHS = ['^/public.*','^/$','^/static.*','^/admin$', '^/media.*']

# A dictionary of path regexes mapping to the roles. A user needs to have all roles in order to be authorized
ROLES = {
'^/admin.*': ['admin']
}

DEFAULT_ROLES = ['iitd_user']
DEFAULT_ROLES = ['iitd_user','yearbook_user']
UNAUTHORIZED_HANDLER = lambda request: HttpResponse("Alas You are out of scope! Go get some more permissions dude",status=401)

code2dept = {
Expand Down Expand Up @@ -78,22 +78,22 @@ def __call__(self, request):
if(token is not None):
try:
decoded = jwt.decode(token,self.public_key,algorithms='RS256')
logging.info("jwt.decode run successfully")
# logging.info("jwt.decode run successfully")

if(float(decoded['exp']) - time.time() < MAX_TTL_ALLOWED):
decoded['user'] = self.refresh(request=request,token={SSO_TOKEN:token})
logging.info("self.refresh executed")
# logging.info("self.refresh executed")

if(not self.authorize_roles(request, decoded['user'])):
logging.info("line 88")
# logging.info("line 88")
return UNAUTHORIZED_HANDLER(request)
self.assign_user(request, decoded['user'])
logging.info("user assigned")
# logging.info("user assigned")

except Exception as err:
# print(err)
logging.info("line 95")
logging.info(err)
# logging.info("line 95")
# logging.info(err)
return self.redirect(request)
else:
try:
Expand All @@ -106,7 +106,7 @@ def __call__(self, request):

except Exception as err:
print(err)
logging.info("line 109")
# logging.info("line 109")
return self.redirect(request)

response = self.get_response(request)
Expand Down

0 comments on commit 8c3d9ee

Please sign in to comment.