gestioCOF/kfet/middleware.py
2016-09-02 01:24:14 +02:00

21 lines
755 B
Python

# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from django.http import HttpResponseForbidden
from kfet.backends import KFetBackend
class KFetAuthenticationMiddleware(object):
def process_request(self, request):
kfet_backend = KFetBackend()
temp_request_user = kfet_backend.authenticate(request)
if temp_request_user:
request.real_user = request.user
request.user = temp_request_user
if request.user.has_perm('kfet.is_team'):
try:
request.user.profile.account_kfet
except RelatedObjectDoesNotExist:
return HttpResponseForbidden