You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
1.2 KiB

from django.contrib.auth.models import User
from cashonly.core.models import Account
from cashonly.core.services import AccountManager
class UsernameCardnumberPinBackend(object):
def authenticate(self, username=None, card_number=None, pin=None):
if username is not None and card_number is not None:
raise ValueError('username and card_number are mutually exclusive')
if username is None and card_number is None:
raise ValueError('either username and card_number is required')
try:
if username is not None:
user = User.objects.get(username=username)
account = user.account
elif card_number is not None:
account = Account.objects.get(card_number=card_number)
except User.DoesNotExist:
return None
except Account.DoesNotExist:
return None
accmgr = AccountManager(account)
if accmgr.check_pin(pin):
return account.user
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None