fix typo + pep8 + del future imports

This commit is contained in:
Aurélien Delobelle 2017-05-10 12:49:14 +02:00
parent 6cdb791989
commit b0e7ebfbc5

View file

@ -1,15 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
import hashlib import hashlib
from django.contrib.auth.models import User, Permission from django.contrib.auth.models import User, Permission
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from kfet.models import Account, GenericTeamToken from kfet.models import Account, GenericTeamToken
class KFetBackend(object): class KFetBackend(object):
def authenticate(self, request): def authenticate(self, request):
password = request.POST.get('KFETPASSWORD', '') password = request.POST.get('KFETPASSWORD', '')
@ -18,13 +15,15 @@ class KFetBackend(object):
return None return None
try: try:
password_sha256 = hashlib.sha256(password.encode('utf-8')).hexdigest() password_sha256 = (
hashlib.sha256(password.encode('utf-8'))
.hexdigest()
)
account = Account.objects.get(password=password_sha256) account = Account.objects.get(password=password_sha256)
user = account.cofprofile.user return account.cofprofile.user
except Account.DoesNotExist: except Account.DoesNotExist:
return None return None
return user
class GenericTeamBackend(object): class GenericTeamBackend(object):
def authenticate(self, username=None, token=None): def authenticate(self, username=None, token=None):
@ -48,7 +47,7 @@ class GenericTeamBackend(object):
try: try:
return ( return (
User.objects User.objects
.select_related('profile__acount_kfet') .select_related('profile__account_kfet')
.get(pk=user_id) .get(pk=user_id)
) )
except User.DoesNotExist: except User.DoesNotExist: