forked from DGNum/gestioCOF
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
from django.contrib.auth import get_user_model
|
|
from kfet.models import Account, GenericTeamToken
|
|
|
|
from .utils import get_kfet_generic_user
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class KFetBackend(object):
|
|
def authenticate(self, request):
|
|
password = request.POST.get('KFETPASSWORD', '')
|
|
password = request.META.get('HTTP_KFETPASSWORD', password)
|
|
if not password:
|
|
return None
|
|
|
|
try:
|
|
return Account.objects.get_by_password(password).user
|
|
except Account.DoesNotExist:
|
|
return None
|
|
|
|
|
|
class GenericTeamBackend(object):
|
|
def authenticate(self, username=None, token=None):
|
|
valid_token = GenericTeamToken.objects.get(token=token)
|
|
if username == 'kfet_genericteam' and valid_token:
|
|
return get_kfet_generic_user()
|
|
return None
|
|
|
|
def get_user(self, user_id):
|
|
try:
|
|
return (
|
|
User.objects
|
|
.select_related('profile__account_kfet')
|
|
.get(pk=user_id)
|
|
)
|
|
except User.DoesNotExist:
|
|
return None
|